I am a new user to R and am trying to use the RNOAA package to get some average weather data for discrete periods of time.
I can get the data from the ncdc code in the RNOAA package and turn this into a data frame but I am having difficulty getting lapply to work for just the mean of the values for the time period.
PRCP_2002a<- ncdc(datasetid='GHCND', datatypeid ='PRCP', startdate = '2001-08-13', enddate = '2002-02-13', stationid='x', token = 'x', limit = 500)
this is done for a large number of time periods. I want to use lapply to extract a data frame from the 'ncdc dataset' object type that I receive from ncdc for each time period.
P1 <- PRCP_2002a$data
Prcp_list = list(P1, P2, P3, P4, etc)
Then use lapply
to go over the list of data frames and calculate the mean of the fourth column (value) and append it to a list.
I tried this code from another help thread here but it gives me a list of lists which includes na's from all the metadata fields that the ncdc includes in the original object.
means<- lapply(Prcp_list, function (x) lapply(x, mean, na.rm= TRUE))
Any help is greatly appreciated and I apologize in advance for any poor choices in code.