| saveat_func | R Documentation |
Internal function used to save the data frame at specific times in case save_at is not equal to dt in the simulation specifications.
saveat_func(df, time_col, new_times)
df |
data.frame in wide format |
time_col |
Name of the time column |
new_times |
Vector of new times to save the data frame at |
Interpolated data.frame. The data frame has columns time followed by
one column per variable.
# Recommended: Use save_at in sim_specs() to downsample simulations
sfm <- xmile("SIR") |> sim_specs(dt = 0.01, save_at = 1)
sim <- simulate(sfm)
df <- as.data.frame(sim)
nrow(df) # Returns only times at intervals of 1
head(df)
# The saveat_func() is the underlying function used by simulate()
# Direct use is not recommended, but shown here for completeness:
sfm <- sfm |> sim_specs(save_at = 0.01)
sim <- simulate(sfm)
df <- as.data.frame(sim)
nrow(df) # Many more rows
# Manual downsampling (not recommended - use save_at instead)
new_times <- seq(min(df$time), max(df$time), by = 1)
df_wide <- as.data.frame(sim, direction = "wide")
df_manual <- saveat_func(df_wide, "time", new_times)
nrow(df_manual)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.