[R] the difference between "x1" and x1
Francisco J. Zagmutt
gerifalte28 at hotmail.com
Fri Apr 21 01:43:03 CEST 2006
Is this what you are after?
Or I just didn't understand what you are trying to accomplish?
PS: try to avoid using names that are already reserved to a function like
"data" See ?data
>From: Chad Reyhan Bhatti <bhatticr at stat.rice.edu>
>To: R-help at stat.math.ethz.ch
>Subject: [R] the difference between "x1" and x1
>Date: Thu, 20 Apr 2006 18:02:02 -0500 (CDT)
>I am not sure what to write in the subject line, but I would like to take
>a character string that is a variable in a data frame and apply a function
>that takes a numeric argument to this character string.
>Here is a simplified example that would solve my problem.
>Imagine I have my data stored in a data frame.
> > x1 <- x2 <- x3 <- x4 <- x5 <- rnorm(20,0,1);
> > data <- as.data.frame(cbind(x1,x2,x3,x4,x5));
>I have a vector containing the variables of interest as such.
> > model.list <- c("x1","x3","x4");
> > model.list
>I would like to loop through this vector and apply the floor() function to
>each variable. In the current form the elements of model.list do not
>represent the variables in the data frame.
> > floor(model.list)
>Error in floor(model.list) : Non-numeric argument to mathematical
> > floor(eval(model.list))
>Error in floor(eval(model.list)) : Non-numeric argument to mathematical
> > s <- expression(paste("floor(",model.list,")",sep=""))
> > s
>expression(paste("floor(", model.list, ")", sep = ""))
> > eval(s)
>I have tried the obvious (to me) without success. Perhaps someone could
>solution and some tidbits for me to read up on about the how and why.
>Chad R. Bhatti
>R-help at stat.math.ethz.ch mailing list
>PLEASE do read the posting guide!
More information about the R-help