
R language: A Quick Reference is about learning R Programming with a short description of the widely used commands. It will help the learner and intermediate user of the R Programming Language to get help with different functions quickly. This Quick Reference is classified into different groups. Let us start with R Language: A Quick Reference – II.
This R Language: A Quick Reference contains R commands about creating vectors, matrices, lists, data frames, arrays, and factors. It also discusses about setting the different properties related to R language data types.
Creating Vectors in R Language
R command | Short Description |
---|---|
c(a1, a2, …, an) | Concatenates all $n$ elements to a vector |
logical(n) | Creates a logical vector of length $n$ (containing false) |
numeric(n) | Creates a numeric vector of length $n$ (containing zeros) |
character(n) | Creates a character vector of length $n$ (containing an empty string) |
complex(n) | Creates a complex vector of length $n$ (containing zeros) |
Creating Lists in R Language
R Command | Short Description |
---|---|
list(e1, e2, … ek) | Combines all $k$ elements as a list |
vector(k, “list”) | Creates a list of length $k$ (the elements are all NULL) |
Creating Matrices in R Language
R Command | Short Description |
---|---|
matrix(x, nr = r, nc = c) | Creates a matrix from $x$ (column as major order) |
matrix(x, nr = r, nc = c) | Creates a matrix from $x$ (row as major order) |
Creating Factors in R Language
R Command | Short Description |
---|---|
factor(x) | Creates a factor from the values of variable $x$ |
factor(x, levels = 1) | Creates a factor with the given level set from the values of the variable $x$ |
ordered(x) | Creates an ordered factor with the given level set from the values of the variable $x$ |
levels(x) | Gives the levels of a factor or ordered factor |
levels(x) = v | Set or reset the levels of a factor or ordered factor |
Creating a Data Frame in R Language
R Command | Short Description |
---|---|
data.frame(n1=x1, n2=x2, ….) | Creates a data frame |
R Language Data Type Properties
R Command | Short Description |
---|---|
length(x) | Gives the number of elements in a variable $x$ |
mode(x) | Tells about the data type of the variable $x$ |
nrow(x) | Displays the number of rows of a vector, array, or data frame $x$ |
ncol(x) | Displays the number of columns (variable) of a vector, array, or data frame $x$ |
dim(x) | Displays the dimension (number of rows and columns) of a matrix, data frame, array, or list $x$ |
row(x) | Matrix of row indices for matrix-like object $x$ |
col(x) | Matrix of column indices for matrix-like object $x$ |
rownames(x) | Get the row names of the matrix-like object $x$ |
rownames(x)=v | Set the row names of the matrix-like object $x$ to $v$ |
colnames(x) | Get the column names of the matrix-like object $x$ |
colnames(x)=v | Set the column names of the matrix-like object $x$ to $v$ |
dimnames(x) | Get both the row and column names (in a matrix, data frame, or list) |
dimnames(x)=list(rn, cn) | Set both the row and column names |
names(x) | Gives the names of $x$ |
namex(x)=v | Sets or resets the names of $x$ to $v$ |
names(x)=NULL | removes the names from $x$ |
row.names(df) | Gives the observation names from a data frame |
row.names(df)=v | Sets or resets the observation names of a data frame |
names(df) | Gives the variables names from a data frame |
names(df)=v | Sets or resets the variable names of a data frame |