|
Combine values into vector |
|
Sequence from m to n (can’t do spacing) |
seq(from=1,to=10,by=2)
|
Sequence with step. For decreasing step, by must be -ve |
seq(from=3,to=27,length.out=40)
|
Sequence with as many numbers specified |
rep(x=c(3,62,8.3),times=3,each=2)
|
Repeat values. The value for times provides the number of times to repeat x, and each provides the number of times to repeat each element of x. |
sort(x=c(2.5,-1,-10,3.44),decreasing=FALSE)
|
Sort a vector in increasing or decreasing order |
|
Determines how many entries exist in a vector given as the argument x |
|
Retrieve specific elements from a vector |
myvec[-1] myvec[-c(1,3,5)]
|
Delete elements by using negative versions of the indexes |
|
Retrieve elements from a vector with a sequence of indices from m to n |
|
Multiply all elements in a vector |
matrix(data=c(-3,2,893,0.17),nrow=2,ncol=2,byrow=FALSE)
|
Create a matrix filled in a column-by-column fashion |
|
Bind together vectors as rows of a matrix |
cbind(c(1,4),c(2,5),c(3,6))
|
Bind together vectors as columns of a matrix |
dim(mymat)
nrow(mymat)
ncol(mymat)
|
Provides the dimensions of a matrix |
|
Refers to the elements in all the rows of column n of the matrix A |
|
Refers to the elements in all the columns of row n of the matrix A |
|
Refers to the elements in all the rows between columns m and n of the matrix A |
|
Refers to the elements in all the columns between rows m and n of the matrix A |
|
Refers to the elements in rows m through n and columns p through q of the matrix A. |
Indexing can be done using individual indices in vectors. To delete or omit elements from a matrix, use negative indexes. |
|
Create an identity matrix of size 3 x 3 |
|
Identify the values along the diagonal of a square matrix |
|
Find the transpose of a matrix |
|
Find the inverse of a matrix |
list(matrix(data=1:4,nrow=2,ncol=2),c(T,F,T,T),"hello")
|
Create a list containing mixed object types. To name the components of a list as it’s being created, assign a label to each component in the list command |
|
Access the ith element of a list |
|
Returns a sublist of selected elements |
|
Name list components to make the elements more recognizable and easier to work with |
|
Access element by name (or create new column) |
|
Add a nested list to an existing list |
data.frame(person=c("Peter","Lois","Meg","Chris","Stewie"), age=c(42,40,17,14,1), gender=factor(c("M","F","F","M","M")), stringsAsFactors=TRUE)
|
Create a data frame. stringsAsFactors is used to control automatic conversion of character strings to factors |
|
Logical Subset Subset rows where gender is M |
Data frames are treated like matrices, so you can also use functions like nrow(df). |