Learn R Programming

apsimx (version 2.8.0)

add_column_apsim_met: Add a column to an object of class ‘met’

Description

The usual way of adding a column to a data frame might not work for an object of class ‘met’, so this method is recommended

Usage

add_column_apsim_met(met, value, name, units)

# S3 method for met $(x, name) <- value

remove_column_apsim_met(met, name)

Value

an object of class ‘met’ with the additional column

an object of class ‘met’ without the variable (column) in ‘name’

Arguments

met

object of class ‘met’

value

value for the data.frame. It could be an integer, double or vector of length equal to the number of rows in x.

name

name of the variable to be removed

units

units for the new column (required)

x

object of class ‘met’

Examples

Run this code
# \donttest{
extd.dir <- system.file("extdata", package = "apsimx")
ames <- read_apsim_met("Ames.met", src.dir = extd.dir)

## The recommended method is
val <- abs(rnorm(nrow(ames), 10))
ames <- add_column_apsim_met(ames, value = val, name = "vp", units = "(hPa)")

## This is also possible
vp <- data.frame(vp = abs(rnorm(nrow(ames), 10)))
attr(vp, "units") <- "(hPa)"
ames$vp <- vp$vp

## This is needed to ensure that units and related attributes are also removed
ames <- remove_column_apsim_met(ames, "vp")
## However, ames$vp <- NULL will also work
# }


Run the code above in your browser using DataLab