[R] Counting the number of non-NA values per day

Tim Chatterton tim.chatterton at uwe.ac.uk
Tue Aug 11 19:26:14 CEST 2009


I have a long dataframe ("pollution") that contains a column of hourly 
date information ("date") and  a column of  pollution  measurements ("pol")

I have been happily calculating daily means and daily maximums using the 
aggregate function

 DMEANpollution =  aggregate(pollution["pol"], 
format(pollution["date"],"%Y-%j"), mean, na.rm = TRUE)
 DMAXpollution =  aggregate(pollution["pol"], 
format(pollution["date"],"%Y-%j"), max, na.rm = TRUE)

However, I also need to count the number of valid measurements for each 
day to check that the mean and max are likely to be valid (for example I 
need at least 18 hourly measurements to calculate a valid daily mean)

Try as I might I have not found a simple way of doing this.
Can anybody help please?

Many thanks,
Tim.

-- 


__________________________________________

Dr Tim Chatterton
Senior Research Fellow
Air Quality Management Resource Centre
Faculty of Environment and Technology
University of the West of England
Frenchay Campus
Bristol
BS16 1QY

Tel: 0117 328 2929
Fax: 0117 328 3360
Email: Tim.Chatterton at uwe.ac.uk




More information about the R-help mailing list