What does this R command translate into in plain English?

  • Thread starter Thread starter user366312
  • Start date Start date
  • Tags Tags
    English
Click For Summary

Discussion Overview

The discussion revolves around the interpretation of a specific R command, focusing on understanding its components and the overall purpose of the command within the context of matrix operations. Participants explore the calculation of the mean based on the command and the reasoning behind its structure.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant calculates the mean of a specific set of values from a matrix and questions the correctness of their understanding.
  • Another participant breaks down the R command into steps, asking for clarification on each part and providing a final answer of 0.5 based on the provided matrix.
  • A participant expresses that they figured out the answer independently but appreciates the help, while also emphasizing the importance of understanding the method used to arrive at the answer.
  • Another participant critiques the focus on the final answer rather than the method, highlighting the value of a systematic approach to understanding the command.
  • One participant reflects on the time spent understanding the command and acknowledges the value of the reasoning process, while clarifying that their previous comments were not meant to undermine others' efforts.

Areas of Agreement / Disagreement

Participants express differing levels of appreciation for the method of reasoning versus the final answer, indicating a lack of consensus on the focus of the discussion. Some participants emphasize the importance of understanding the process, while others are more concerned with the outcome.

Contextual Notes

The discussion includes varying interpretations of the R command and its components, with participants not fully agreeing on the significance of the method versus the result. There are also indications of differing levels of understanding and engagement with the material.

user366312
Gold Member
Messages
88
Reaction score
3
TL;DR
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
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   Reactions: sysprog
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.
 
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.
 
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.
 
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.
 

Similar threads

Replies
11
Views
1K
  • · Replies 11 ·
Replies
11
Views
2K
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 57 ·
2
Replies
57
Views
6K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 31 ·
2
Replies
31
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
59
Views
10K