[R] # values used in a function in tapply

From: Stephanie Shaw <slshaw23_at_gmail.com>
Date: Fri, 14 Nov 2008 15:47:40 -0800


Hello,

I am using tapply to pull out data by the day of week and then perform functions (e.g. mean). I would like to have the number of values used for the calcuation for the functions, sorted by each day of week. A number of entries in any given column are NAs.

I have tried the following code and simple variants with no luck.

for (i in 1:length(a[1,])){
 x<-tapply(a[,i],a[,1],mean, na.rm=TRUE)  amn<-tapply(a[,i],a[,1],colSums(!is.na),na.rm=T)} Adding an explicit argument to colSums(!is.na) {e.g. colSums(!is.na(a[,i]))} produced an error that said colSums was not a function. Trying an imbedded tapply instead of the colSums didn't work either. Using the sum function added the values, not the count of the values.

Thank you for any suggestions,
Stephanie

        [[alternative HTML version deleted]]



R-help_at_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. Received on Fri 14 Nov 2008 - 23:50:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 15 Nov 2008 - 00:30:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive