Re: [R] A question about data frame

From: Phil Spector <spector_at_stat.berkeley.edu>
Date: Thu, 10 Mar 2011 14:19:52 -0800

Gang -

    It sounds like you want your character variables to be stored as character values, not factor values. If that's the case, use

df = data.frame(n, s,stringsAsFactors=FALSE)

If you want them to be factors, but not to display as factors, others have provided usable solutions.

On Thu, 10 Mar 2011, Gang Chen wrote:

> A very simple question. With a data frame like this:
>
>> n = c(2, 3, 5)
>> s = c("aa", "bb", "cc")
>> df = data.frame(n, s)
>
> I want df$s[1] or df[1,2], but how can I get rid of the extra line in
> the output about the factor levels:
>
>> df$s[1]
> [1] aa
> Levels: aa bb cc
>
> Thanks,
> Gang
>
> ______________________________________________
> 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.
>



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 Thu 10 Mar 2011 - 22:30:13 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 Fri 11 Mar 2011 - 03:30:20 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