set_value: Set user defined values

View source: R/ff_set_value.R

set_valueR Documentation

Set user defined values

Description

Specify specific values between dates.

Usage

set_value(x, col_name, out_name = NULL, value, from, to)

Arguments

x

data frame or tibble with class Date or POSIX* in the first column.

col_name

string with column(s) name(s) to set.

out_name

optional. String with new column(s) name(s). If you set it as NULL, the function will overwrite the original data frame.

value

numeric vector with the numeric values to set between dates (from and to). If you provide a number it will be recycled. When using a multiple dates (i.e.: "date" vector in from and to) use a list with a numeric vector inside each element.

from

string vector for 'Date' class or POSIX* class for date-time data with the starting date.

to

string vector for 'Date' class or POSIX* class for date-time data with the ending date.

Value

The same table but with the set numeric values between the dates.

Examples


# create a data frame
dates   <- seq.Date(from = as.Date('1990-01-01'), to = as.Date('1990-12-01'), by = 'm')
met_var <- runif(n = 12, 0, 10)

met_table <- data.frame(dates, met_var)

# set single value recycling
set_value(x = met_table, col_name = 'met_var', value = 10,
 from = '1990-01-01', to = '1990-06-01' )

# set different periods
set_value(x = met_table, col_name = 'met_var', value = list(NA_real_, c(1, 2) ),
 from = c('1990-01-01', '1990-11-01'), to = c('1990-06-01', '1990-12-01') )

# now set as new columns
set_value(x = met_table, col_name = 'met_var', out_name = 'met_set',
 value = list(NA_real_, c(1, 2) ),
 from = c('1990-01-01', '1990-11-01'),
  to = c('1990-06-01', '1990-12-01') )


hydrotoolbox documentation built on April 14, 2023, 12:34 a.m.