Skip to content
Prev 240754 / 398500 Next

Create Matrix of 2 Dim from two vectors

Hi,

First, create a MATRIX of the correct size:
xy <- matrix(nrow=3, ncol=3)

Then, in your for loop, you need to index each cell correctly, like this:
xy[i,j]

Finally, if you want to assign "1,4" to each cell, you need to paste 
x[i] and y[j] together, like this:
xy[i,j]<-paste(x[i],y[j], sep=",")

With the brackets if you want:
xy[i,j]<-paste("(", x[i], ",", y[j], ")", sep="")

Or easier like this:
xy <- matrix(rep(x,3),nrow=3, ncol=3)
apply(xy, 1, FUN=paste, y, sep=",")

HTH,
Ivan

Le 11/8/2010 11:15, abotaha a ?crit :