[R] how to get the numbers of factors in a matrix
Liu, Jun Yi
7yuny1 at gmail.com
Tue Jan 21 10:12:06 CET 2014
Dear YZ,
I guess this is what you want:
1. http://stackoverflow.com/questions/3418128/how-to-convert-a-factor-to-an-integer-numeric-without-a-loss-of-information
2. http://stackoverflow.com/questions/6979625/arithmetic-operations-on-r-factors/6980780#6980780
3. http://toddjobe.blogspot.jp/2010/08/converting-r-contingency-tables-to-data.html
but beware of that “If you really want the levels of the factor to be used, you're either doing something very wrong or too clever for its own good."
All the best
JY
------------------------------------------------------
From: 张以春 yczhang at nigpas.ac.cn
Reply: 张以春 yczhang at nigpas.ac.cn
Date: 21 January 2014 at 16:57:38
To: r-help at r-project.org r-help at r-project.org
Subject: [R] how to get the numbers of factors in a matrix
>
> Dear friends,
>
>
> I have a question do not know how to resolve.
>
>
> I have a big matrix composed of different columns (I use N here).
> A column is "species" and another one is "latitudes". Now, I want
> to know how I can get the number of different "latitudes" for every
> "species". I have tried to split the matrix according to species
> (X<-split(N, N$species) and then use sapply(X, function(m){nlevels(m$latitudes)})
> to get that. But the result shows the total factor numbers of "latitudes"
> but not the factor numbers of every species I splitted. Also,
> I have tried to use tapply(N$latitudes, N$species, nlevels)
> to do this. The result is the same. I am confused about this. Can
> someone help me with that? Thank you very much!
>
>
> Best regards,
> Yichun
>
>
>
>
>
>
> [[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.
>
More information about the R-help
mailing list