Professional Documents
Culture Documents
R Programming
R Programming
Datatypes in R:
Vector
Matrix
Array
List
Data Frame
R studio
Single/Multiple line(s) of codes execution - Scripting area
Single line of codes execution - Console
Environment Area - Variable Operations
Install Packages/Help/Plots - 4th Workspace
vtr1 = c(TRUE,FALSE) = TRUE FALSE
vtr2 = c(3,3.12,TRUE) = 3.0, 3.12, 1.0
vtr3 = c(3,TRUE,"HELLO") = "3", "TRUE", "HELLO"
class(vtr3)
m1 = 1:4
dim(m1) = c(2,2)
m1
[,1] [,2]
[1,] 1 3
[2,] 2 4
Arrays are R data objects which can store data in more than 2 dimensions
array(data , dim , dimnames)
arr = array(c(1:9),dim = c(3,3,4,2))
arr
, , 1, 1
, , 2, 1
, , 3, 1
, , 4, 1
, , 1, 2
, , 2, 2
, , 3, 2
, , 4, 2
, , 1, 1
, , 1, 2
vtr = c(TRUE)
vtr12 = c(1,2.2)
vtr13 = c("Hi")
mylist1 = list(vtr,vtr12,vtr13)
mylist1
[[1]]
[1] TRUE
[[2]]
[1] 1.0 2.2
[[3]]
[1] "Hi"
Data Frame: A Table or a 2-d array in which each columns have values of one
variable and each row has one set of values in each column
If we have to load table from db or excel, load it in a dataframe. Eg:
data.frame(data)
vtr1 = c(1:5)
vtr2 = c("Emily","Paukeen","Emma", "Arknov","Alex")
vtr3 = c(3.2,2,4,6,9.2)
data.frame(vtr1,vtr2,vtr3)
print(5%/%2) = 2 #Floor
print(5%%2) = 1 #Modulus
value1 = c(TRUE,FALSE,TRUE,FALSE)
value2 = c(FALSE,TRUE,TRUE,FALSE)
print(value1&value2)
FALSE FALSE TRUE FALSE
Element wise OR
print(value1 | value2)
TRUE TRUE TRUE FALSE