[R] Pulling columns out of a data.frame

Jim Lemon bitwrit at ozemail.com.au
Fri Aug 10 13:26:02 CEST 2001


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list