RP: Week 1
10 Jun 2014####Basic atomic classes of objects
- character
- numeric
- integer
- complex
- logical
####Vector vs List
Vector: objects of the same class
vector(<class>, <length>)
List: can contain objects of different classes
####Numbers
- default double precision real number
- 1L-> explicitly integer 1
-
Inf
1 / 0 = Inf 1 / Inf = 0
-
NaN: not a number
0 / 0 = NaN
####Attributes
- names, dimnames
- dimensions
- class
- length
- other user-defined attributes/metadata
- attributes()
####Assignment
<-
####Integer sequence
1:20
####Creating vectors
- c(0.5, 0.6)
- vector(“numeric”, length = 10)
####Explicit coercion
- as.class function
- Nonsensical coercion results in NAs
####Matrices
-
dim()
return nrow, ncol
- it’s constructed column-wise
-
creating from vector
m <- 1:10 dim(m) <- c(2,5)
-
creating by column-binding or row-binding
cbind() rbind()
####Factors
- labels
- levels
####Missing values
- NA
- NaN
- is.na()
- is.nan()
- NA values have a class too.
- NaN is NA
- NA is not NaN
####Data frames
- row.names
- read.table() or read.csv()
- data.matrix()
####Names
R objects can have names
names()
List elements can also have names
dimnames()
###Subsetting
- []
- [[]]
- $
####Subsetting a Matrix
drop = FALSE
will result in a matrix
otherwise will result in a vector(in most case)
####Partial matching
x<-list(aardvark=1:5)
x$a #aardvark
x[["a", exact = FALSE]]
####Reading and writing data
- dput: single object
- dump: multiple objects
Your Comments
comments powered by Disqus