Filter observation list to exclude situations, variables or dates

filter_obs(
  obs_list,
  var = NULL,
  situation = NULL,
  dates = NULL,
  include = FALSE,
  var_names = lifecycle::deprecated(),
  sit_names = lifecycle::deprecated()
)

Arguments

obs_list

List of observed values to use for parameter estimation. A named list (names = situations names) of data.frame containing one column named Date with the dates (Date or POSIXct format) of the different observations and one column per observed variables with either the measured values or NA, if the variable is not observed at the given date. See details section for more information on the list of observations actually used during the parameter estimation process.

var

(optional, if not given all variables will be kept) Vector containing the names of the variables to include or exclude

situation

(optional, if not given all situations will be kept) Vector containing the names of the situations to include or exclude

dates

(optional, if not given all dates will be kept) Vector containing the dates (POSIXct format) to include or exclude

include

(optional, FALSE by default) Flag indicating if the variables / situations / dates listed in inputs must be included (TRUE) or not (FALSE) in the resulting list

var_names

[Deprecated] var_names is no longer supported, use var instead.

sit_names

[Deprecated] sit_names is no longer supported, use situation instead.

Value

obs_list List of filtered observed values (same format as obs_list input argument)

See also

For more detail and examples, see the different vignettes in CroptimizR website

Examples


obs_list <- list(
  sit1 = data.frame(
    Date = as.POSIXct(c("2009-11-30", "2009-12-10")),
    var1 = c(1.1, 1.5), var2 = c(NA, 2.1)
  ),
  sit2 = data.frame(
    Date = as.POSIXct(c("2009-11-30", "2009-12-5")),
    var1 = c(1.3, 2)
  )
)

# Keep only var1
filter_obs(obs_list, var = c("var1"), include = TRUE)
#> $sit1
#>         Date var1
#> 1 2009-11-30  1.1
#> 2 2009-12-10  1.5
#> 
#> $sit2
#>         Date var1
#> 3 2009-11-30  1.3
#> 4 2009-12-05  2.0
#> 

# Exclude observations at date "2009-11-30"
filter_obs(obs_list, dates = as.POSIXct(c("2009-11-30")))
#> $sit1
#>         Date var1 var2
#> 1 2009-12-10  1.5  2.1
#> 
#> $sit2
#>         Date var1
#> 2 2009-12-05    2
#>