Is there a way to use the cycle variable for rowname? v=1:6 for (a in 1:3){ for (b in 4:5) { v=rbind(v,a.b=1) } } v This above obviously does not work, but I couldn't find out how to use a and b to construct a rowname like 14, 15, 24, 25. Thanks for the help. Balazs -- View this message in context: http://www.nabble.com/using-for-variable-as-rowname-tp19533203p19533203.html Sent from the R help mailing list archive at Nabble.com.
> Is there a way to use the cycle variable for rowname? > > v=1:6 > for (a in 1:3){ > for (b in 4:5) { > v=rbind(v,a.b=1) > } > } > v > > This above obviously does not work, but I couldn't find out how to use aand> b to construct a rowname like 14, 15, 24, 25.Not pretty, but this does the trick. v=1:6 nam <- "?" for (a in 1:3){ for (b in 4:5) { v <- rbind(v,1) nam <- c(nam, paste(a,b,sep=".")) } } rownames(v) <- nam v Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:20}}
On 17-Sep-08 14:22:11, Ralikwen wrote:> > Is there a way to use the cycle variable for rowname? > > v=1:6 > for (a in 1:3){ > for (b in 4:5) { > v=rbind(v,a.b=1) > } > } > v > > This above obviously does not work, but I couldn't find out how to use > a and > b to construct a rowname like 14, 15, 24, 25. > Thanks for the help. > BalazsI don't know of a way to construct a paramater-name out of variable values (so that "a.b" is a dynamic name as intended in your v=rbind(v,a.b=1) ), though possibly someone else does! However, something along the following lines would work (you construct a vector of row names, along with v, within the loop, and then apply it at the end): v<-(1:6) a.b<-"0" for (a in 1:3){ for (b in 4:5) { a.b<-c(a.b,paste(a,".",b,sep="")) v=rbind(v,1) } } rownames(v)<-a.b v # [,1] [,2] [,3] [,4] [,5] [,6] # 0 1 2 3 4 5 6 # 1.4 1 1 1 1 1 1 # 1.5 1 1 1 1 1 1 # 2.4 1 1 1 1 1 1 # 2.5 1 1 1 1 1 1 # 3.4 1 1 1 1 1 1 # 3.5 1 1 1 1 1 1 Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 17-Sep-08 Time: 16:02:18 ------------------------------ XFMail ------------------------------
Thanks for your help, I didn't know where you can or can't use a for variable. Seems that I have to use rownames to do this anyway, so finally I went for a more procedural solution: v=1:6 for (a in 1:3){ for (b in 4:5) { v<-rbind(v,1+a+b:6+a+b) rownames(v)[nrow(v)]= paste(a,b,sep=".") } } Ralikwen wrote:> > Is there a way to use the cycle variable for rowname? >Thanks again. Bal?zs -- View this message in context: http://www.nabble.com/using-for-variable-as-rowname-tp19533203p19549904.html Sent from the R help mailing list archive at Nabble.com.
Apparently Analagous Threads
- Error setting rowname if rowname currently NULL
- LDAP pass_filter seems to be not working
- Sort matrix with duplicate row names alphabetically by rowname
- Package Hmisc, functions summary.formula() and latex(), options pdig, pctdig, eps and prmsd
- squid transparent proxy problem