To convert a data frame column to a vector, you can use the following:
Using the [[ ]] (double square brackets) to extract the atomic values from the data frame.
a1 = c(1, 2, 3, 4, 5)
a2 = c(6, 7, 8, 9, 10)
a3 = c(11, 12, 13, 14, 15)
aframe = data.frame(a1, a2, a3)
avector <- aframe[['a2']]
avector
[1] 6 7 8 9 10
class(avector)
[1] "numeric"
Using the following syntax:
avector <- aframe[,2]avector
[1] 6 7 8 9 10
class(avector)
[1] "numeric"
Using the pull function from the dplyr package.
pull(aframe, a2)
[1] 6 7 8 9 10
class(pull(aframe, a2))
[1] "numeric"