[R] Multiplying elements of vectors
Mariana Martinez-Morales
marianamartinezmorales at gmail.com
Sun Feb 6 03:34:09 CET 2011
Hi guys:
Sorry if this question is very basic. I’m learning basic matrix and
vectors multiplication to develop a population matrix model for
plants. I’m trying to multiply the elements of two vectors (each of
the “x” values by each of the “y” values) to obtain a square matrix of
xy values.
f.e.
x<-seq(5,205)
y<-seq(5,20,5)
stages<-c(“Sdl”, “Juv”, “Ad1”, “Ad2”)
If I just multiply xy as a matrix
xy<-matrix(x,y,nrow=4,ncol=4,dimnames=list(stages,stages))
I obtain this
xy
Sdl Juv A1 A2
Sdl 5 10 15 20
Juv 5 10 15 20
A1 5 10 15 20
A2 5 10 15 20
but what I want to obtain is this matrix
Sdl Juv A1 A2
Sdl 25 50 75 100
Juv 50 100 150 200
A1 75 50 225 300
A2 100 200 300 400
More information about the R-help
mailing list