jj367 jj367 -3 years ago 64
R Question

R - How to set named value from data frame

I have a data frame that currently stores multiple variables to be used through the remainder of my R script, example data frame structured as follows:

VarName VarDefinition
VarA 1
VarB 2


Is it possible to loop through the table to define the named values VarA (equal to 1) and VarB (equal to 2) as per the details in the table?

Answer Source

Hope the following helps your case:

> for(i in 1:nrow(varT)) {
    assign(paste(varT$Varname[i]), varT$VarDefinition[i])
  }

> VarA
[1] 1

> VarB
[1] 2
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download