The “as….” explicitly converts the data to whatever you desired outcome.
- as.array(x)
- as.data.frame(x)
- as.numeric(x)
- as.logical(x)
- as.vector(x)
- as.matrix(x)
- as.complex(x)
- as.character(x)
- … convert type; for a complete list, use methods(as)
to one long vector |
to matrix |
to data frame |
|
from vector |
c(x,y) | cbind(x,y) rbind(x,y) |
data.frame(x,y) |
from matrix |
as.vector(mymatrix) | as.data.frame(mymatrix) | |
from data frame |
as.matrix(myframe) |
If you are interested in testing data types use “is…” instead of “as…” this will allow R to return a TRUE or FALSE outcomes.