Hi > > Hello, > > I know that it'll be quite easy to do what I want but somehow I am lost as > I am new to R. I want to get summary results arranged by groups. In detail > I'd like get the number (levels) of Species per Family like for this dataset: > > SPEC <- factor(c("a","a","b","b","c","c","c","d","e","e","e","e")) > FAM <- factor(c("A","A","A","A","B","B","B","C","C","C","C","C")) > df <- data.frame(SPEC,FAM) > > I tried tapply(SPEC, FAM, nlevels).. but it is not the result I am looking for... > > What is the easiest way to do that? Do I have to rearrange the dataset?
To do what? Do you want number of unique entries within each level of FAM? If yes sapply(tapply(SPEC, FAM, unique), length) can do this. Regards Petr > > Best regards and Happy New Year! > > Johannes > > -- > > ______________________________________________ > 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. ______________________________________________ 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.