Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

get.var

Get named variable or evaluate expression from list or data.frame


Description

This routine takes a text string and a data frame or list. It first sees if the string is the name of a variable in the data frame/ list. If it is then the value of this variable is returned. Otherwise the routine tries to evaluate the expression within the data.frame/list (but nowhere else) and if successful returns the result. If neither step works then NULL is returned. The routine is useful for processing gam formulae. If the variable is a matrix then it is coerced to a numeric vector, by default.

Usage

get.var(txt,data,vecMat=TRUE)

Arguments

txt

a text string which is either the name of a variable in data or when parsed is an expression that can be evaluated in data. It can also be neither in which case the function returns NULL.

data

A data frame or list.

vecMat

Should matrices be coerced to numeric vectors?

Value

The evaluated variable or NULL. May be coerced to a numeric vector if it's a matrix.

Author(s)

Simon N. Wood simon.wood@r-project.org

References

See Also

Examples

require(mgcv)
y <- 1:4;dat<-data.frame(x=5:10)
get.var("x",dat)
get.var("y",dat)
get.var("x==6",dat)
dat <- list(X=matrix(1:6,3,2))
get.var("X",dat)

mgcv

Mixed GAM Computation Vehicle with Automatic Smoothness Estimation

v1.8-35
GPL (>= 2)
Authors
Simon Wood <simon.wood@r-project.org>
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.