[R] eval parse question

Joshua Wiley jwiley.psych at gmail.com
Wed Jun 20 10:47:27 CEST 2012


Hi Sebastian,

Probably, but I suspect the "correct" answer is simply do not do it
that way.  Instead of:

test1 <- 1:10
test2 <- 11:20
...
test5 <- 41:50
testt5[7] <- .435

do

test <- list(1:10, 11:20, 21:30, 31:40, 41:50)

then it is as easy as

test[[5]][7] <- .435

Cheers,

Josh

On Wed, Jun 20, 2012 at 12:59 AM, Leuzinger  Sebastian
<sebastian.leuzinger at env.ethz.ch> wrote:
> Dear all
>
> Is there a more efficient way of achieving the following (assigning to an indexed vector in a loop):
>
> test5 <- 1:10
> eval(parse(text=paste("test",5,"[",7,"]<- ",0.435,sep="")))
>
> this works, but it is probably very slow.
>
> Thanks
> Sebastian Leuzinger
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/



More information about the R-help mailing list