Quantcast

eval parse question

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

eval parse question

Leuzinger  Sebastian
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
______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: eval parse question

Joshua Wiley-2
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
<[hidden email]> 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
> ______________________________________________
> [hidden email] 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/

______________________________________________
[hidden email] 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.
Loading...