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 suggestions?
See the following code: a<-c("Abraham","Jonah","Moses") b<-c("Sarah","Hannah","Mary") c<-c("Billy","Joe","Bob") df<-data.frame(a=a,b=b,c=c) #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! ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.