1

I have a 3-dimensional array with dim = c(50,100,12). Now I want to access the grid point that corresponds to the one-dimensional index 123. I want to obtain a vector of 12 values from grid point 123. How do I achieve that? Thanks a lot!

1
  • as.vector(ThreeD)[123:134] ? Commented May 23, 2018 at 20:11

2 Answers 2

2

With R, you have a choice of indexing with arrays and matrices. You can use the dimensional indexing or you can use vector indexng. Just use:

myArray[123:(123+11) ]
Sign up to request clarification or add additional context in comments.

4 Comments

So it wasn't an array. Terminology is important in these matters. It appears you intended (or at least should have intended) to say that you were accessing a nested list and that the index was c(3, 2, 1).
We can only guess at what "this" might have been. It would not be surprising if my suggestion failed with a list. It was designed to work with an array. Post a reproducible example if you are still having problems.
It is a nested list, right. It is one list of 12 lists with each of them containing one array.... That is why I tried climate[[i]][k][d,f,g]. Isn't it possible that way?
Not likely that way. Possibly climate[[i]][[k]][c(d,f,g)] but an example would be needed to be sure. Or you can post the results of str(.) on the object of interest.
0

Well, I finally solved the problem by converting the vector indices into array indices using the R base package implemented function arrayInd(ind, dim). It returns a two-dimensional matrix with the corresponding array indices that looks like that:

   [,1] [,2]
 [1,]  207  129
 [2,]  197  138
 [3,]  199  136
 [4,]  205  131

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.