I have a dataframe, for example:
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)
I tried the following to convert one of the columns to a vector, but it does not work:
avector <- as.vector(aframe['a2']) class(avector) [1] "data.frame"
This is the only solution I could come up with, but I assume that there should be a better way to do this:
class(aframe['a2']) [1] "data.frame" avector = c() for(atmp in aframe['a2']) { avector <- atmp } class(avector) [1] "numeric"
Note: My dictionary above may be turned off, so please correct me if so. I am still exploring the world of R. Also, any explanation of what is going on here is appreciated (for example, regarding Python or some other language, it would help!)
type-conversion vector r dataframe
Dolan Antenucci Aug 15 '11 at 20:08 2011-08-15 20:08
source share