[R] assigning differences in a loop

Marc Schwartz MSchwartz at mn.rr.com
Sun Feb 26 23:20:40 CET 2006


On Sun, 2006-02-26 at 16:04 -0600, Marc Schwartz wrote:

> Lacking your data, which I presume is ECG measurement information from
> the acronyms in use, you could do something like this:
> 
> for(i in c("13","26","38")) { 
>     for (j in c("HR","PQ","QRS","QT")){
>        nam1<-paste("d",j,i,sep="")
>        nam2<-paste(j,i,sep=".")
>        nam3<-paste(j,"0",sep=".")
>        eval(parse(text = paste(nam1, " <- ", nam2, " - ", nam3,  "\n")))
>       }}

Quick correction here. I accidentally left in the 'newline' in the last
line above. This is a remnant of testing with print(). It should be:

for(i in c("13","26","38")) { 
    for (j in c("HR","PQ","QRS","QT")){
       nam1<-paste("d",j,i,sep="")
       nam2<-paste(j,i,sep=".")
       nam3<-paste(j,"0",sep=".")
       eval(parse(text = paste(nam1, " <- ", nam2, " - ", nam3)))
      }}


Marc




More information about the R-help mailing list