On Dec 3, 2009, at 2:14 PM, Peng Cai wrote: > Also, can I control for number of decimal places printed. Like when > I use "mean" function. By default it shows upto 7 dec. Thanks!
> print(4.567891234, digits=3) [1] 4.57 > > > On Thu, Dec 3, 2009 at 2:08 PM, Peng Cai <pengcaimaill...@gmail.com> > wrote: > Thanks David for your suggestions. > > > On Thu, Dec 3, 2009 at 2:03 PM, David Winsemius <dwinsem...@comcast.net > > wrote: > > On Dec 3, 2009, at 1:50 PM, Peng Cai wrote: > > Hi R Users, > > I'm wondering how can I calculate two (or three) way sum of a > variable. A > sample data is: > > State Month Year Value > NC Jan 1996 1 > NC Jan 1996 2 > NC Feb 1997 2 > NC Feb 1997 3 > NC Mar 1998 3 > NC Mar 1998 4 > NY Jan 1996 4 > NY Jan 1996 5 > NY Feb 1997 5 > NY Feb 1997 6 > NY Mar 1998 6 > NY Mar 1998 7 > > I'm trying to sum up "value" column by State*Month and by > State*Month*Year. > > ?tapply > > as in > > sum.tbl <- with(dftbl, tapply(Value, list(State, Month), sum) ) > > > Also, I may need to calculate mean value along with "sum". > > Use the mean function in the above formulation to get means, length > to get counts, or perhaps summary .... or one of the several > packages that offer a "describe" function. So many functions, so > little time. > > -- David > > > > Any help would be greatly appreciated, > > Thanks, > Peng > > [[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. > > David Winsemius, MD > Heritage Laboratories > West Hartford, CT > > > David Winsemius, MD Heritage Laboratories West Hartford, CT [[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.