I have a list dataframes
of 288 ASCII data frames in R that contain values and their coordinates. The data are for the average temperature of every hour by month, so the data frames have titles that range from jan_01
to dec_24
. What I want to do is restrict these so they are reduced to only containing values for a specific range (region) of coordinates. I can do this successfully for each individual frame using lower bound xl
and upper bound xu
. For example, the x-coordinates for 01:00 in April would be restricted by using
apr_01 <- apr_01[apr_01$x <= xu,]
apr_01 <- apr_01[apr_01$x >= xl,]
I suspect there's some way to use lapply()
or a series of loops so that this operation can be done to all data frames for the whole year, but I couldn't figure out how to implement it since my method above needs the unique data frame name. I tried writing a generalizable function for use with lapply()
, but I'm new to R so haven't had much luck. This is probably a trivial problem, but any help would be appreciated!
edit: The function I tried to write, which obviously won't work, was something like
restrict <- function(f){
f <- f[f$s1 <= xu]
f <- f[f$s1 >= xl]
}
for(i in 1:24){
apr_[i] <- restrict(apr_[i])
}