[R] the name of a variable in a function

juli g. pausas juli at ceam.es
Wed Sep 17 20:27:49 CEST 2003


Dear collegues,
How can I get the name of a variable (and not the variable) within a 
function ?
For instance, in the following function, I'd like to create a variable 
in the dataframe df with the same name to the variable passed in var:


prova <- function( var )
{
  df <- as.data.frame(matrix(nr=20,nc=0))
  df[["here"]] <- seq(min(var), max(var), le= 20)   #
  df
}

for instance,

a <- 1:50
prova(a)

should give a dataframe with a variable called a (df$a)
Thanks in advance

Juli




More information about the R-help mailing list