Replace elements in a data.frame or vector of length > 1 by name

replace_vecelements(x, varnms, vals)

Arguments

x

A vector or data.frame.

varnms

Variable names to match: Specify position by name and index.

vals

Vector of values to insert at the specified positions.

Value

The vector or data.frame in x with the elements 'varnms' replaced by vals.

Examples

soil_materials <- data.frame(ths = rep(0.4,3), alpha = rep(23.1, 3))

varnms = c("soil_materials.ths3", "soil_materials.ths1", "soil_materials.alpha2")
vals = c(0.999, 0.001, 99)
soil_materials
#>   ths alpha
#> 1 0.4  23.1
#> 2 0.4  23.1
#> 3 0.4  23.1
replace_vecelements(soil_materials, varnms, vals)
#>   alpha   ths
#> 1  23.1 0.001
#> 2  99.0 0.400
#> 3  23.1 0.999

x <- set_paramLWFB90()[["pdur"]]
varnms <- c("pdur2", "pdur12")
vals <- c(0,10)
x
#>  [1] 4 4 4 4 4 4 4 4 4 4 4 4
replace_vecelements(x, varnms, vals)
#>  [1]  4  0  4  4  4  4  4  4  4  4  4 10