R type how to set vector code example

Example 1: r type of all columns

sapply(my.data, class)
        y        x1        x2        X3 
"numeric" "integer" "logical"  "factor"

Example 2: r create a vector

# Basic syntax:
c(11, 23, 42) # Vector of numerics
c(TRUE, FALSE, TRUE) # Vector of booleans/logicals
c("aa", "bb", "cc") # Vector of strings

# Note, in R, list and vectors (aka atomic vectors) are both 
#	one-dimensional objects, but lists can contain mixed type data 
#	whereas vectors can only contain one type of data
# Note, to make a list, use: list(11, 23, 42)

Tags:

R Example