Dear Jun Yi,
Thank you very much for your help. But, the link you attached can not resolve my question.
What I want is to get the numbers of factor levels for every subsets of a vector. When I do this, it always gives me the total numbers of levels for the whole vector. It really makes me confused.
Best,
Yichun
> -----原始邮件-----
> 发件人: "Liu, Jun Yi" <7yuny1@gmail.com>
> 发送时间: 2014年1月21日 星期二
> 收件人: "张以春" , r-help@r-project.org
> 抄送:
> 主题: Re: [R] how to get the numbers of factors in a matrix
>
>
> 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@nigpas.ac.cn
> Reply: 张以春 yczhang@nigpas.ac.cn
> Date: 21 January 2014 at 16:57:38
> To: r-help@r-project.org r-help@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@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.
> >
>
--
Dr Yichun Zhang
State Key Laboratory of Palaeobiology and Stratigraphy, Nanjing Institute of Geology and Palaeontology
39 East Beijing Road, Nanjing, China, 210008
[[alternative HTML version deleted]]