Furthermore, aggregate passes extra arguments to FUN, so explicit declaration of na.rm = T can be done in the call to aggregate directly:
aggregate(cbind(v1, v2) ~ v3, data = testDF, FUN = mean, na.rm = T) HTH, Jon On Tue, May 17, 2011 at 5:22 AM, Jannis <bt_jan...@yahoo.de> wrote: > Andy, > > > have a look at ?mean. The na.omit argument set to TRUE should solve your > problem. The use in aggregate would be something like: > > aggregate(x = testDF, by = list(testDF$v3), FUN = function(x) > mean(x,na.rm=TRUE)) > > > > HTH > Jannis > > > > On 05/17/2011 04:27 AM, Andrew McFadden wrote: >> >> Hi R users >> >> I trying to some aggregate statistics on a very large dataset. The null >> values are causing a problem. I would like to calculate aggregate values >> for groups. I am just no sure how to deal with the "" I would ideally >> like them to ignored ie if there is only 1 value over several columns >> than that value would be the summary statistic. >> >> I have put the following example together to show my problem. >> >> testDF<- data.frame(v1 = c(1,3,5,7,8,3,5,NA,4,5,7,9), >> v2 = c(11,33,55,77,88,33,55,NA,44,55,77,99), >> >> v3=c("red","red","red","red","red","red","blue","blue","blue","blue","bl >> ue","blue")) >> >> aggregate(x = testDF, by = list(testDF$v3), FUN = "mean") >> >> For this example I would like to get a mean value for red (v1=4.5; v1=5) >> and blue (v1=49.5; v2=55) >> >> Thank you in advance. >> >> Andy >> >> Andrew McFadden MVS BVSc >> Incursion Investigator >> Investigation& Diagnostic Centres - Wallaceville Biosecurity New >> Zealand Ministry of Agriculture and Forestry >> >> Phone 04 894 5600 Fax 04 894 4973 Mobile 029 894 5611 Postal address: >> Investigation and Diagnostic Centre- Wallaceville Box 40742 Ward St >> Upper Hutt >> >> >> >> >> >> This email message and any attachment(s) is intended solely for the >> addressee(s) >> named above. The information it contains is confidential and may be >> legally >> privileged. Unauthorised use of the message, or the information it >> contains, >> may be unlawful. If you have received this message by mistake please call >> the >> sender immediately on 64 4 8940100 or notify us by return email and erase >> the >> original message and attachments. Thank you. >> >> The Ministry of Agriculture and Forestry accepts no responsibility for >> changes >> made to this email or to any attachments after transmission from the >> office. >> >> [[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. >> > > ______________________________________________ > 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. > -- =============================================== Jon Daily Technician =============================================== #!/usr/bin/env outside # It's great, trust me. ______________________________________________ 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.