assuming your data is called dat, you can use: tapply(dat$sc, INDEX=list(p=dat$p, aa=dat$aa), var)
see ?tapply and ?var I hope this helps Francisco Aimin Yan wrote: > I have data like this > > aa p sc > met p1 34 > met p1 56 > met p2 45 > met p2 33 > ser p1 34 > ser p1 56 > ser p2 45 > ser p2 33 > .... > > I want to estimate the following variances for: > sc in p1 for met > sc in p2 for met > sc between p1 and p2 for met > sc for met > > sc in p1 for ser > sc in p2 for ser > sc between p1 and p2 for ser > sc for ser > > > Does anybody how to write code for this? > > ______________________________________________ > R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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.