[R] converting the string columns in a data.frame to factors?

From: John Edwards <jhnedwards603_at_gmail.com>
Date: Mon, 28 Feb 2011 11:13:40 -0600


Dear All,

I'm not sure if I understand the parameter stringsAsFactors correctly. I'm trying to convert the string columns in aframe1 to factors. But it seems stringsAsFactors=T in as.data.frame() doesn't do anything. Could anybody let know what is the correct way to converting strings to factors?

> aframe1=data.frame(x=LETTERS[1:10], y=LETTERS[1:10], stringsAsFactors=F)
> aframe2=as.data.frame(aframe1, stringsAsFactors=T)
>
> str(aframe1)

'data.frame': 10 obs. of 2 variables:
 $ x: chr "A" "B" "C" "D" ...
 $ y: chr "A" "B" "C" "D" ...
> str(aframe2)

'data.frame': 10 obs. of 2 variables:
 $ x: chr "A" "B" "C" "D" ...
 $ y: chr "A" "B" "C" "D" ...
>

Thanks,
John

        [[alternative HTML version deleted]]



R-help_at_r-project.org 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. Received on Mon 28 Feb 2011 - 17:17:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Feb 2011 - 17:40:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive