Accessing n-dimensional array in R using a function of vector of indexes

sda

my program in R creates an n-dimensional array.

PVALUES = array(0, dim=dimensions)

where dimensions = c(x,y,z, ... )

The dimensions will depend on a particular input. So, I want to create a general-purpose code that will:

  1. Store a particular element in the array
  2. Read a particular element from the array

From reading this site I learned how to do #2 - read an element from the array

ll=list(x,y,z, ...)
element_xyz = do.call(`[`, c(list(PVALUES), ll))

Please help me solving #1, that is storing an element to the n-dimensional array.


Let me rephrase my question

Suppose I have a 4-dimensional array. I can store a value and read a value from this array:

PVALUES[1,1,1,1] = 43 #set a value
data = PVALUES[1,1,1,1] #use a value

How can I perform the same operations using a function of a vector of indexes:

indexes = c(1,1,1,1)
set(PVALUES, indexes) = 43
data = get(PVALUES, indexes) ?

Thank you

sda

Thanks for helpful response.

I will use the following solution:

PVALUES = array(0, dim=dimensions) #Create an n-dimensional array
dimensions = c(x,y,z,...,n)

Set a value to PVALUES[x,y,z,...,n]:

y=c(x,y,z,...,n)
PVALUES[t(y)]=26

Reading a value from PVALUES[x,y,z,...,n]:

y=c(x,y,z,...,n)
data=PVALUES[t(y)]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to declare std::vector with an 'n' dimensional array?

From Dev

Accessing SSE vector registers using array notation

From Dev

Transforming a one-dimensional, "flattened" index into the N-dimensional vector index of an N-dimensional array

From Dev

HashMap n-dimensional using a recursive function

From Dev

Recursive Variadic Template Function For N-Dimensional Vector

From Dev

Index n-dimensional array with vector and a blank/dummy index

From Dev

How to access n dimensional array using recursion

From Dev

Python: Accessing elements of multi-dimensional list, given a list of indexes

From Dev

Getting indexes from two-dimensional array

From Dev

r subset array using vector

From Dev

Accessing a one-dimensional array as a two-dimensional array

From Dev

Two dimensional array as a function

From Dev

Accessing an element of an array through negative indexes

From Dev

Flatten n-dimensional vector

From Dev

Accessing/creating multi dimensional array in Java

From Dev

Accessing Two dimensional fixed byte array

From Dev

Accessing a multi-dimensional array through pointer

From Dev

Accessing Mulit-dimensional non indexed array

From Dev

Accessing Elements in 2-Dimensional Array Elm

From Dev

Accessing multi-dimensional array with one-dimensional index

From Dev

Sorting a multi-dimensional array in JavaScript using a custom sort function

From Dev

Slicing n-dimensional numpy array using list of indices

From Dev

reshaping a view of a n-dimensional array without using reshape

From Dev

Using scipy.interpolate.interpn to interpolate a N-Dimensional array

From Dev

reshaping a view of a n-dimensional array without using reshape

From Dev

Accessing array of function pointers

From Dev

Array Math on n dimensional array

From Dev

Accessing vector index using bitset

From Dev

Accessing vector index using bitset

Related Related

  1. 1

    How to declare std::vector with an 'n' dimensional array?

  2. 2

    Accessing SSE vector registers using array notation

  3. 3

    Transforming a one-dimensional, "flattened" index into the N-dimensional vector index of an N-dimensional array

  4. 4

    HashMap n-dimensional using a recursive function

  5. 5

    Recursive Variadic Template Function For N-Dimensional Vector

  6. 6

    Index n-dimensional array with vector and a blank/dummy index

  7. 7

    How to access n dimensional array using recursion

  8. 8

    Python: Accessing elements of multi-dimensional list, given a list of indexes

  9. 9

    Getting indexes from two-dimensional array

  10. 10

    r subset array using vector

  11. 11

    Accessing a one-dimensional array as a two-dimensional array

  12. 12

    Two dimensional array as a function

  13. 13

    Accessing an element of an array through negative indexes

  14. 14

    Flatten n-dimensional vector

  15. 15

    Accessing/creating multi dimensional array in Java

  16. 16

    Accessing Two dimensional fixed byte array

  17. 17

    Accessing a multi-dimensional array through pointer

  18. 18

    Accessing Mulit-dimensional non indexed array

  19. 19

    Accessing Elements in 2-Dimensional Array Elm

  20. 20

    Accessing multi-dimensional array with one-dimensional index

  21. 21

    Sorting a multi-dimensional array in JavaScript using a custom sort function

  22. 22

    Slicing n-dimensional numpy array using list of indices

  23. 23

    reshaping a view of a n-dimensional array without using reshape

  24. 24

    Using scipy.interpolate.interpn to interpolate a N-Dimensional array

  25. 25

    reshaping a view of a n-dimensional array without using reshape

  26. 26

    Accessing array of function pointers

  27. 27

    Array Math on n dimensional array

  28. 28

    Accessing vector index using bitset

  29. 29

    Accessing vector index using bitset

HotTag

Archive