r - Getting an element from an array using a vector as an index -


given k_matrix matrix

> k=4; > k_matrix = array(runif(k*k) , dim = rep(2,k), dimnames = null) > k_matrix  , , 1, 1            [,1]      [,2] [1,] 0.3919999 0.2033387 [2,] 0.7053074 0.6531753  , , 2, 1            [,1]      [,2] [1,] 0.9474465 0.6097955 [2,] 0.7115899 0.8040770  , , 1, 2             [,1]      [,2] [1,] 0.01687723 0.6536963 [2,] 0.91289535 0.5464496  , , 2, 2            [,1]      [,2] [1,] 0.3858341 0.7031602 [2,] 0.7991189 0.1577894 

if execute,

> k_matrix[2,1,1,1] [1] 0.7053074 

i "second" element. however, if try same result using vector (vec) contains coordinates of second element, this:

> vec = c(2,1,1,1) > k_matrix[vec] [1] 0.7053074 0.3919999 0.3919999 0.3919999 

,which not expected result. how can can solve issue?


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -