On Jan 2, 2012, at 11:14 AM, Johannes Radinger wrote:
Thank you Petr,
that is exactly what I was looking for... no I played a little bit
around with that because I want to create a summary with FAM as a
grouping variable. Beside the number of unique SPEC per FAM also
want to get their levels as text. So far I know I have following:
paste(unique(SPEC), collapse = ', ')
But how can I use that in combination with tapply and furthermore
with cbind like:
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)
with(df, cbind("Number of
SPEC"=sapply(tapply(SPEC,FAM,unique),length),
"SPECs"=tapply(SPEC,FAM,unique)))
You probably do not want yoru resutls coming back as tables (which is
what tapply returns, but as vectors.) So use `ave` instead of `tapply`.
The result should look like:
Number of SPEC SPECs
A 2 "a, b"
B 1 "c"
C 2 "d, e"
Thank you,
/johannes
David Winsemius, MD
West Hartford, CT
______________________________________________
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.