Skip to content
Prev 156265 / 398506 Next

using for variable as rowname

On 17-Sep-08 14:22:11, Ralikwen wrote:
I 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 ------------------------------