What does this R command translate into in plain English?

  • Thread starter user366312
  • Start date
  • Tags
    English
In summary, the conversation centered around understanding a specific command and its purpose in a given matrix. The mean of the command was calculated to be 1.25, and there was discussion about the innermost-first innermore-next approach used to parse the expression. There was also mention of the time and effort spent to understand the command.
  • #1
user366312
Gold Member
89
3
TL;DR Summary
mean(mat[2, mat[1, ] == 1] == 1)

What does this R command translate into plain English?
According to my understanding:

243198

So the mean is: (1+1+2+1)/4 = 1.25.

Is my understanding correct?

If I am correct, what does it actually try to achieve?
 
Technology news on Phys.org
  • #2
user366312 said:
mean(mat[2, mat[1, ] == 1] == 1)

Why would anyone write a command like that?

It helps to break the problem down into steps:
  • First, consider what does mat[1,] evaluate as?
  • Next, what is the output of mat[1,]==1?
  • Next, what is mat[2, mat[1, ] == 1]?
  • Next, what is mat[2, mat[1, ] == 1] == 1?
  • Finally, you can calculate mean(mat[2, mat[1, ] == 1] == 1).
Given the matrix you provide in the OP, I get 0.5 as the final answer.
 
  • Like
Likes sysprog
  • #3
Ygggdrasil said:
Given the matrix you provide in the OP, I get 0.5 as the final answer.

Yeah, I figured that out myself.

Thanks for the help anyway.
 
  • #4
user366312 said:
Yeah, I figured that out myself.

Thanks for the help anyway.
That response looks as if you cared mainly about the answer, and not so much about the specifics of the clarifyingly cogent method carefully elucidated by @Ygggdrasil by which he arrived at it.

I'm sure your gratitude is appreciated by him; however, your edification would be immensely more gratifying.

Please at least don't fail to notice the value of the innermost-first innermore-next approach taken to parsing the expression.
 
  • #5
sysprog said:
That response looks as if you cared mainly about the answer, and not so much about the specifics of the clarifyingly cogent method carefully elucidated by @Ygggdrasil by which he arrived at it.

I'm sure your gratitude is appreciated by him; however, your edification would be immensely more gratifying.

Please at least don't fail to notice the value of the innermost-first innermore-next approach taken to parsing the expression.

Speculation is bad for health!

I spent almost 4 hours on this to understand it properly.
 
  • #6
user366312 said:
Speculation is bad for health!

I spent almost 4 hours on this to understand it properly.
I didn't mean to disparage the value of your thinking things through for yourself. When I posted, I of course could not see all the avenues of your reasoning, and was responding merely as an observer of the prior posts. Thanks for reading and responding to what I wrote.
 

1. What is R and why is it used?

R is a programming language and software environment commonly used for statistical computing and graphics. It is used by scientists, researchers, and statisticians to analyze and visualize data.

2. What is the purpose of translating R commands into plain English?

Translating R commands into plain English helps to make the code more understandable and accessible to those who are not familiar with the programming language. It also allows for easier communication and collaboration among team members.

3. How do I translate an R command into plain English?

To translate an R command into plain English, you can break down the code into smaller, more manageable parts and explain each step in simple terms. You can also use comments or annotations within the code to provide explanations.

4. Can I translate R commands into other languages besides English?

Yes, R commands can be translated into other languages such as Spanish, French, or Chinese. However, the translated commands may not always be exact translations and may vary depending on the language and context.

5. Is it necessary to translate R commands into plain English?

It is not necessary to translate R commands into plain English, but it can be helpful in some situations. For example, when working with a team or presenting results to non-technical audiences, translating the code can make it easier for others to understand and interpret the results.

Similar threads

  • Programming and Computer Science
Replies
1
Views
459
Replies
11
Views
792
Replies
1
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
10
Views
1K
  • Programming and Computer Science
2
Replies
57
Views
3K
  • Programming and Computer Science
Replies
2
Views
989
  • Programming and Computer Science
Replies
31
Views
2K
Replies
9
Views
1K
Replies
6
Views
618
Back
Top