resample_sim: get subset of time from a generic timeseries data.frame

View source: R/resample_sim.R

resample_simR Documentation

get subset of time from a generic timeseries data.frame

Description

resamples the input data.frame to only have rows corresponding to matches between df$DateTime and t_out. Both df$DateTime and t_out are of type POSIXct, and the precision of the match is passed in through the precision argument. The order of t_out, not df$DateTime is retained.

Usage

resample_sim(df, t_out, method = "match", precision = "days")

Arguments

df

a data.frame with DateTime and potentially other columns

t_out

a vector of POSIXct dates (or character array that can be coerced into POSIXct) for matching to df$DateTime

method

'match' for exact match or 'interp' for temporal interpolation

precision

matching precision (must be 'secs', 'mins','hours', 'days', or 'exact').

Value

a data.frame with DateTime other original columns, resampled according to t_out

Author(s)

Jordan S. Read

See Also

get_temp, get_wind, get_surface_height, get_evaporation, get_ice

Examples

sim_folder <- run_example_sim(verbose = FALSE)
nc_file <- file.path(sim_folder, 'output/output.nc')
temp_surf <- get_temp(nc_file, reference = 'surface', z_out = c(0,1,2))
t_out <- as.POSIXct(c("2011-04-01", "2011-06-14", "2011-04-05", "2011-07-28"))
temp_out <- resample_sim(df = temp_surf, t_out = t_out)

t_out <- c("2011-04-01 10:00", "2011-04-05 08:15", 
      "2011-06-14 10:30", "2011-04-05 10:21", 
      "2011-07-28 10:00")
temp_out <- resample_sim(df = temp_surf, t_out = t_out, precision = 'days')

temp_out <- resample_sim(df = temp_surf, t_out = t_out, method = 'interp', precision = 'hours')

USGS-R/glmtools documentation built on March 26, 2024, 5:43 p.m.