CIND123 Module 2
CIND123 Module 2
Length(x)
x[3] gets the third element of x
y <- x[-2]
Skips the second element of a vector
y <- c(x[1:3], 300, x[4])
x{1:3] is the first few elements of a vector
z <- x[-c(1:3)]
Excludes elements 1:3
Data types in R
Numeric
Character
Date
Logical
Numeric
x = 1.5
class(x)
Or is.numeric(x)
Is.integer
R will store y=10 as an integer
use z = as.integer(15)
Character data
is.character(x)
Factor command
y <- factor(“data”)
Date
Date1 <- as.Date(“2012-06-28”)
class(date1)
as.Date(05/06/2007”, “%m/%d?%Y”)
Custom date orders
True = 1
True * 5 = 5
Logical Data
k <- TRUE
class(k)
“logical”
> 2 == 3 (false)
>2 != 3 (true)
Matrices
m (rows) by n (column)
mean(asdasd, na.rm=T)
Use factor for ordinal data