On 1 Mar 2007 at 12:17, Aimin Yan wrote:

Date sent:              Thu, 01 Mar 2007 12:17:09 -0600
To:                     [email protected]
From:                   Aimin Yan <[EMAIL PROTECTED]>
Subject:                [R] number of levels for a factor

> I have temp list which have 19 data.frame
> I want to get number of levels for pr in the first dat.frame
> I do this like this:
> temp[[1]]$pr just has "1A24"
> after I do nlevels(temp[[1]]$pr)
> I expect to get 1, but I get 19
> 
> anyone know why?

Hi

help page for [.factor tells you that using subsetting results in

A factor with the same set of levels as x unless drop=TRUE.

I presume your list resulted from some splitting operation and that 
original set of levels was preserved.

HTH
Petr


> 
>  > tail(temp[[1]]$pr)
> [1] 1A24 1A24 1A24 1A24 1A24 1A24
> 19 Levels: 1A24 1A57 1A5J 1A6X 1AB7 1AF8 1AFI 1AGG 1AH9 1AHL 1AJ3 1AJW
> ... 1AZK
>  > nlevels(temp[[1]]$pr)
> [1] 19
> 
> Aimin
> 
> ______________________________________________
> [email protected] 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.

Petr Pikal
[EMAIL PROTECTED]

______________________________________________
[email protected] 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.

Reply via email to