Re: [R] assigning differences in a loop

From: Marc Schwartz <MSchwartz_at_mn.rr.com>
Date: Mon 27 Feb 2006 - 09:20:40 EST

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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Feb 27 09:29:28 2006

This archive was generated by hypermail 2.1.8 : Mon 27 Feb 2006 - 12:08:47 EST