[R] why doesn't as.character of this factor create a vector of characters?
yee at post.harvard.edu
Tue Jul 10 17:56:41 CEST 2007
I'm trying to figure out why when I use as.character() on one row of a
data.frame, I get factor numbers instead of a character vector. Any
See the following code:
#Suppose I'm interested in one line of this data frame but as a vector
one.line <- df[df$a=="Abraham",]
#However the following illustrates the problem I'm having
one.line <- as.vector(df[df$a=="Abraham",]) #Creates a one row
data.frame instead of a vector!
#compare above to
one.line <- as.character(df[df$a=="Abraham",]) #Creates a vector of 1, 3, 1!
#In the end, this creates the output that I'd like:
one.line <-as.vector(t(df[df$a=="Abraham",])) #but it seems like a lot of work!
More information about the R-help