Re: [R] strange behavior of matrix

2010-04-05 Thread Phil Spector
William - An interesting feature of matrix indexing in R is that if you provide a two column matrix as a subscript, you are refering to the elements whose indices are in the rows of the matrix. This is extremely handy for converting tables to matrices: m = cbind(c(1,1,1,2,2,2,3,3,3),c(1,2,

[R] strange behavior of matrix

2010-04-05 Thread William Revelle
Dear R list, I have discovered a seemingly peculiar feature when using a matrix to index itself (yes, this is strange code, which I have now modified to be more reasonable). #this makes sense s <- matrix(1:3,nrow=1) s[s]#all three elements are shown #but when I try s <- matrix(1:2,n