3

I'm a total beginner in "R". I'm doing a science research work, and I need to translate a R code (package) into Python (or C++, or whatever). I need help to understand what the matrix command (with parameters) below is doing. Here is a copy/paste from the Programiz site where I'm running the code and parallely check with my Python translation whether the results are the same. Here, I want to know precisely what the ee <- matrix(edges[details.min.ind,], no.of.current.steps, 4) instruction is doing exactly (with parameters exposed below). I've searched the documentation and other posts, but it is far from clear to me what this specific instruction is doing.

[1] "details.min.ind >> " 
[1] 3 
[1] "no.of.current.steps >> " 
[1] 1
[1] "edges >> " [,1] [,2] [,3] [,4] 
[1,]    1    2    3    0 
[2,]    2    3    4    0 
[3,]    3    4    5    0 
[4,]    4    5    6    0 
[5,]    5    6    7    0 
[6,]    6    7    8    0 
[7,]    7    8    9    0
ee <- matrix(edges[details.min.ind,], no.of.current.steps, 4)

Can someone explain to me the exact effect of the above instruction?

Thank you very much.

I've tried to understand what the instruction does, but my understanding is very partial. And I'd like to understand the syntaxe and what it does more genrally (not simply on that single example).

1 Answer 1

2

R is really well documented, and you can browse through the (non-compiled) source code of any function if you want. As ?matrix explains, this is the function signature:

matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL)

So your call turns the third row of edges (subset by [details.min.ind,]) into a 1x4 matrix (nrow=no.of.current.steps, ncol=4).

I'm not sure what your general logic is as R will quite aggressively recycle inputs, but this particular call could just be replaced by edges[details.min.ind,] which will produce the exact same result.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi and thank you for your reply. I must have made a mistake when I tested it apart from the code, because the result did not look that "logical". I just did it again, and it's perfectly coherent. Thank you again for replying.

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.