Posts

Showing posts from October, 2020

Arrays in R Programming

Image
 DATA TYPE: Graphical Representation of Data Types in R is shown as below: ARRAY: An array is created using the array() function. It is Multi-Dimensional. Syntax: array(data = NA, dim = length(data), dimnames = NULL) Data -                Can be a Vector dim-                   c(x,y,k); x indicates the number of rows, y indicates the number of columns, k                                        denotes the number of Matrices dimnames-   NULL or List 1. Single Dimensional Array a1<-array(1:10) a1  [1]  1  2  3  4  5  6  7  8  9 10 class(a1) [1] "array" 2. Two Dimensional Array a2<-array(1:10,dim=c(5,2)) a2      [,1] [,2] [1,]    1    6 [2,]    2    7 [3,]    3    8 [4,]    4    9 [5,]    5   10 3. Three Dimensional Array Let us create 2X2 matrix of 2  dimension matrix. a3<-array(1:8,dim=c(2,2,2),dimnames=NULL) a3 , , 1      [,1] [,2] [1,]    1    3 [2,]    2    4 , , 2      [,1] [,2] [1,]    5    7 [2,]    6    8 4. Naming Columns And Rows Let us name the array using di

Matrix in R

Image
DATA TYPE: Graphical Representation of Data Types in R is shown as below: MATRIX: Matrix is represented as a two-dimensional structure. It can be created using matrix() function. CREATING MATRIX: a<-matrix(data = c(1:16), nrow = 8, ncol = 2, byrow = TRUE,dimnames = NULL) print(a)           [,1] [,2] [1,]    1    2 [2,]    3    4 [3,]    5    6 [4,]    7    8 [5,]    9   10 [6,]   11   12 [7,]   13   14 [8,]   15   16 nrow-       number of Rows in Matrix ncol-          number of Column in Matrix byrow-      Either TRUE or FALSE. If FALSE (the default) the matrix is filled by columns, otherwise                       matrix is filled by rows. dimnames -Either NULL or List of Length 2. i.e. Rowname and Colum name #Printing Matrix having byrow=False a<-matrix(data = c(1:16), nrow = 8, ncol = 2, byrow = FALSE,dimnames =NULL) print(a)      [,1] [,2] [1,]    1    9 [2,]    2   10 [3,]    3   11 [4,]    4   12 [5,]    5   13 [6,]    6   14 [7,]    7   15 [8,]    8   16 #Printing Matrix w

List in R Programming

Image
 DATA TYPE: Graphical Representation of Data Types in R is shown as below: LIST: An ordered collection of objects. List is Single Dimensional. CREATING A LIST: Let us create list "L1" with  different vector data type L1<-list(1,c(1,2,3),'a',2+3i,TRUE) print(L1) [[1]] [1] 1 [[2]] [1] 1 2 3 [[3]] [1] "a" [[4]] [1] 2+3i [[5]] [1] TRUE NAMING LIST:  We can name the elements in the list. Let us create a list "Stud_data" Stud_data<-list(c("Anu","Abi"),c(100,95),list("Maths")) print(Stud_data) [[1]] [1] "Anu" "Abi" [[2]] [1] 100  95 [[3]] [[3]][[1]] [1] "Maths" names(Stud_data)<- c("Student Name", "Marks Obtained", "Subject") print(Stud_data) $`Student Name` [1] "Anu" "Abi" $`Marks Obtained` [1] 100  95 $Subject $Subject[[1]] [1] "Maths" ACCESSING LIST: We can access the list using the index of the element or using the name. Let

Vector Data Type in R Programming

Image
 Data Type: Graphical Representation of Data Types in R is shown as below: VECTOR Vector Data Type is the Simplest Form of all other data types. Vector is Single Dimensional. It has 6 atomic data types. Graphical View on Vector Data Type is as below Vector is classified as below based on the number of the element it can store. NOTE: Pink font Color indicates "Code". Blue font Color indicates "Output from R Console". Light Green Font Color indicates "Comment" SINGLE ELEMENT VECTOR #A.Logical    v1 <- TRUE    print(v1) [1] TRUE    print(class(v1)) [1] "logical" #B.Numeric     v2<-45   print(v2) [1] 45   print(class(v2)) [1] "numeric" #C.Integer Integer in R is recognized with suffix L.     v3<-67L   print(v3) [1] 67   print(class(v3)) [1] "integer" #D.Complex     v4<-2+3i   print(v4) [1] 2+3i    print(class(v4)) [1] "complex" #E.Character     v5<-"