Hi there Probably a very simple solution to this problem. I have a character vector eg c("name1","name2","name3") and I want to pull out these columns from a data.frame, converting each of these columns into factors also. Many thanks Rachel -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
To pull out a column, say myColumn, you can do something like: myColumn["name1"] or myColumn[c("name1", "name2")] To convert to factor I believe you can use the factor() command. Cheers, Kevin> > From: "Rachel Cunliffe" <rachel at stat.auckland.ac.nz> > Date: Fri, 10 Aug 2001 11:06:42 +1200 > To: "[R]" <r-help at stat.math.ethz.ch> > Subject: [R] Pulling columns out of a data.frame > > Hi there > > Probably a very simple solution to this problem. > > I have a character vector eg c("name1","name2","name3") and I want to pull > out these columns from a data.frame, converting each of these columns into > factors also. > > Many thanks > > Rachel > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >----------------------------------- Ko-Kang Kevin Wang Statistical Analysis Division Leader Software Developers' Klub (SDK) University of Auckland New Zealand -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Rachel Cunliffe wrote:> > ...I have a character vector eg c("name1","name2","name3") and I want to pull > out these columns from a data.frame, converting each of these columns into > factors also.Assuming that the column in your data.frame is named "names", and the data frame is named "mydat", new.names<-as.factor(mydat["names"]) should give you the column of name types as a factor vector. Jim -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Apparently Analagous Threads
- LDA Precdict - Seems to be predicting on the Training Data
- Warning from reshape2 when melting a data frame with uneven number of columns.
- Arranging column data to create plots
- Selecting data frame components by name - do you know a shorter way?
- Off Topic bash question