course from GreatLearning
types
- numeric (ex: 1, 2, 3.4 regardless of float and integer)
- character (string with one quote (') or two ("))
- logical (TRUE / T and FALSE / F, if combine in numeric will be T = 1, F = 0)
- complex (numeric with imaginary factor ex 13+6i)
get the type of var
class(variable)
operators
- assignment
= equal to operator
variable <- value_to_be_assigned
orvalue_to_assigned -> variable
- arithmetic
+ - * /
- relational
> greater than, <, ==, !=
- logical
& and, | or
vector linear homogenous data structure
- using combiner
vec <- c(1,2,3,4,5)
- homogenous mean cannot be different type (ex: numeric and character
- if theres character than all variable converted into char, with order char > numeric > logical
vec[2]
get the second value of variable vecvec[1:3]
get the value of vec from 1 to 3vec[c(1,3)]
get the value of vec on index 1 and 3
list
more like vector, but not homogenous (can have multiple type (num, char, logical, vector).
l1 <- list(a, 'char', T)
class(l1[[1]])
get the type of list index 1
matrix
m1 <- matrix(c(1,2,3,4,5,6), nrow(2), ncol(3), byrow = T)
nrow
is to spread value in number of rowncol
is to spread value in number of colbyrow
is to place the value by T: row first, F: col first- to extract the value inside matrix
m1[row, col]
if row is empty than will extract for all rowm1[, col]
vice versa
array multi dimensional homogenous data structure (multi vector) example
vec1 <- c(1,2,3,4,5,6)
vec2 <- c(7,8,9,10,11,12)
#a1 <- array(c(vec1, vec2), dim=(row, col, numOfElementInArray)
a1 <- array(c(vec1, vec2), dim=(2, 3, 2)
extracting value from array, like getting from dim params
a1[row, col, arrayIndex]
read by taking
- extract from array number index
- get row from that array
- get col from that array
factor and dataframe
- factor: to get the distinct value of a vector
- dataframe: 2 dimensional heterogenous data structure, simply like table in excel
tblx <- data.frame(ColName1=c("v1","v2","v3"), ColName2=c("u1","u2","u3"))
- to get the value of col1
tblx$ColName1
- to view in table wise
view(tblx)
, better to not do viewing on large dataset, will consume memory - we can use tibble package for better viewing