[R] taking daily modes from hourly data

Jim Lemon jim at bitwrit.com.au
Wed Sep 24 10:37:14 CEST 2014


On Tue, 23 Sep 2014 01:40:22 PM maria cabello wrote:
> Dear all,
> I have a data frame (datos) of hourly wind speed and direction with 
4columns
> (1st date, 2nd hour, 3rd wind speed and 4rth wind direction). I have 
been
> able to do the daily mean of the wind speed, but when I try to get the 
more
> frequent wind direction of every day, it doesn't work. I have tried to do
> it with aggregate function, but it only works for mean, max, min...
> 
> mean_wind<- aggregate(datos[range_of_dates,col_wind_speed],
> 
list(date=format(as.Date(datos[range_of_dates,col_dates],"%d/%m/%Y"),"%d/%m/
> %Y")), FUN=mean, na.rm=TRUE)  #it works perfectly
> 
> mode_wind<- aggregate(datos[range_of_dates,col_wind_direction],
> 
list(date=format(as.Date(datos[range_of_dates,col_dates],"%d/%m/%Y"),"%d/%m
> /%Y")), FUN=mode)  #it tells me "numeric"
> 
> Can anyone help me? My data have not the same length for each day, 
I mean,
> for example it is possible that for 1st of January I have 20 hours of 
data,
> but for the 2nd of January I have 24, or the 3rd of January I have 18...so
> I need to aggregate the data to calculate the mean and the mode 
from the
> column of my date... Thanks in advance

Hi Maria,
Have a look at the Mode function in the prettyR package.

Jim



More information about the R-help mailing list