set_value: Set user defined values

Description Usage Arguments Value Examples

View source: R/ff_set_value.R

Description

Specify specific values between dates.

Usage

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

Arguments

x

data frame with class Date or POSIXct in the first column and numeric on the others.

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 POSIXct class for date-time data with the starting Date.

to

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

Value

The same data frame but with the set numeric values between the dates.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 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 July 9, 2021, 1:06 a.m.