matrix - the [] operator in matrices R -


so know if have:

m = matrix(1:9, 3,3) z = as.matrix(expand.grid(1:3, 1:3)) 

and

m[z]  # 1 2 3 4 5 6 7 8 9 

but if

m[] = m[z] # matrix.. 

i'm little confused [] operator does? why doesnt m[][z] or m[z][] return matrix? , how return matrix without assigning variable m[]

thanks!

the key here when argument "[]" (which function) 2 column matrix provided, result vector first column specifies row , second column specifies column in operated-upon matrix. "feature" ( , handy 1 might add) of language.

the arguments might or might not contain of possible combinations of row , column result not predictably sensibly matrix of same dimensions. form: m[] <- m[ z[1:4, ] ] produce result warning. should @ result , make effort understand happening.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -