Skip to content
Prev 309871 / 398513 Next

division giving spurious NA

Hello,

Your behavior is due to the fact that R uses _column_ vectors. The first 
column of x[1:2,] is divided by the first two elements of x[3,], then 
the second column of x[1:2,] by the next two elements of x[3,] and one 
of them is NA. Then the 3rd and 4th columns of x[1:2,], each by two 
elements of x[3,].
To see this think of x[3,] as a matrix with the same number of rows as 
x[1:2,]:

matrix(x[3,], nrow=2)
          [,1]     [,2]
[1,] 3.425393       NA
[2,] 2.534523 3.247219

And superimpose this on x[1:2,] to get the divisions that take place.
To get the rows of x[1:2,] divided by the vector x[3,], use transposes:

t(t(x[1:2,])/x[3,])
           [,1]      [,2] [,3]      [,4]
[1,] 0.7572935 0.3341405   NA 0.6912376
[2,] 0.3548600 0.3248356   NA 0.9782823


Hope this helps,

Rui Barradas
Em 05-11-2012 09:57, Christian Hoffmann escreveu: