Re: [R] levels() function for a vector

From: Richard Pearson <richard.pearson_at_postgrad.manchester.ac.uk>
Date: Tue, 11 Mar 2008 09:12:13 +0000

Karen

levels returns the levels attribute of a variable, and a vector has no such attribute. This is usually used with a factor, e.g.

 > temp <- c(3, 5, 5, NA)
 > levels(factor(temp))
[1] "3" "5"

Best wishes

Richard

Chang Liu wrote:
> Hello:
>
> I'm trying to use levels function, but I don't know why it's returning NULL. For example:
>
>

>> temp[1]  3  5  5 NA> levels(temp)NULL>
>>     

>
> Also, I've tried:
>
>> list(temp)[[1]][1] "3" "5" "5" NA 
>> levels(list(temp))NULL
>>     

> Is there a specific requirement on the parameter?
>
> Karen
>
> _________________________________________________________________
>
>

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

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 Tue 11 Mar 2008 - 09:17:38 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 Tue 11 Mar 2008 - 10:30:21 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