0% found this document useful (0 votes)
60 views7 pages

Worksheet - 3

This document summarizes an R programming lab experiment on data types in R. The student implemented lists, matrices, and arrays. For lists, the student accessed elements, changed an element, checked for inclusion, and manipulated the list. For arrays, the student created 1D and multidimensional arrays and accessed elements. For matrices, the student created a matrix, accessed elements of different rows and columns, added rows and columns, and checked for element inclusion. The student learned to write R programs, use variables and comments, and execute programs in R, RStudio, and the terminal.

Uploaded by

Pushp Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views7 pages

Worksheet - 3

This document summarizes an R programming lab experiment on data types in R. The student implemented lists, matrices, and arrays. For lists, the student accessed elements, changed an element, checked for inclusion, and manipulated the list. For arrays, the student created 1D and multidimensional arrays and accessed elements. For matrices, the student created a matrix, accessed elements of different rows and columns, added rows and columns, and checked for element inclusion. The student learned to write R programs, use variables and comments, and execute programs in R, RStudio, and the terminal.

Uploaded by

Pushp Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Worksheet - 3

Student Name: Pushp Raj Choudhary UID: 19BCS1372

Branch: B.E. CSE Section/Group: 3A


Semester: 5th Date of Performance: 19/09/2021
Subject Name: AIML Lab Subject Code: CSP-303

1. Aim/Overview of the practical:


Write a Rcode to create variables by implementing three different data types namely
1. Lists
2. Matrices
3. Arrays
Also impose the appropriate manipulations.

2. Softwares used: R, RStudio

3. Steps for experiment/practical/Code:

a)LIST:
#list
lt = list("A", "B", "C", "D", "E", "F", "G")
paste(c("List: ",lt), collapse="-->")

#accessing elements in list


paste(c("lt[2] = ", lt[2]), collapse=" ")

#change element in list


lt[2] <- 9
paste(c("New list after changing element 2: ",lt), collapse="-->")
#to check if 9 is in the list or not
paste("9 is present in list: ", 9 %in% lt)

#length of list
paste("length of list: ", length(lt))

#add new element at the end of list


new_lt1 <- append(lt, "end")
paste(c("New list after append new element at End: ",new_lt1), collapse="-->")

#add new element in between of list


new_lt2 <- append(lt, "between", after=4)
paste(c("New list after append new element in between the list: ",new_lt2),
collapse="-->")

#removing elements from the list


lt <- lt[-1]
paste(c("New list after Removing element: ",lt), collapse="-->")

#Accesing Range of index


paste(c("New list after append element at End: ",lt[3:5]), collapse="-->")

Screenshot and Output for list:


b) ARRAY:
arr <- c(1:24)
paste("1-D array: ")
print(arr)
# An array with more than one dimension
multiarray <- array(arr, dim = c(4, 3, 2))
paste("multi dimension array: ")
print(multiarray)

#Accessing array elements


paste(c("arr[2]: ", arr[2]), collapse=" ")

#to check if element is present in the array or not


paste("13 is present in array: ", 13 %in% arr)

#find dimesion of array


paste(c("dimesion of multiarray: ", dim(multiarray)), collapse=" ")

#find length of array


paste(c("length of arr: ", length(arr)), collapse=" ")
SCREENSHOT OF OUTPUT:
c) MATRICES:
#matrix
m = matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9), nrow=3, ncol=3, byrow=TRUE)
print(m)

#Accessing matrix elements


paste(c("Accessing elementsof matrix: ", m[1,2]), collapse=" ")

#Accesing more than one row


paste("accessing more than one row: ")
print(m[c(1, 2),])

#Accesing more than one column


paste("accessing more than one column: ")
print(m[,c(2, 3)])

#Adding rows and column in matrix


new_m <- rbind(m, c(10, 20, 30))
new_m <- cbind(new_m, c(40, 50, 60, 0))
paste('New matrix after adding row and column: ')
print(new_m)

#to check if element is present in matrix or not


paste("30 is present in matrix: ", 30 %in% new_m)

#find dimension
paste(c("dimnesion of new_m: ", dim(new_m)), collapse=" ")

#length of matrix
paste("length of new_m: ", length(new_m))
SCREENSHOT AND OUTPUT FOR MATRICES:
Learning outcomes (What I have learnt):

1. Learnt to write programs in R

2. Learnt about variables and comments in R

3. Learnt to execute program in R, RStudio and Terminal

Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
2.
3.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy