What does this R command translate into in plain English?

  • Thread starter Thread starter user366312
  • Start date Start date
  • Tags Tags
    English
AI Thread Summary
The discussion revolves around understanding a specific command in matrix manipulation, particularly the calculation of the mean using the expression mean(mat[2, mat[1, ] == 1] == 1). The initial poster calculates the mean of a given matrix and arrives at a value of 1.25, but later clarifies that the final answer is actually 0.5 after breaking down the command into steps. The conversation emphasizes the importance of a systematic approach to parsing complex expressions, highlighting the value of understanding the methodology behind calculations rather than just focusing on the final answer. There is also a mention of the time spent on grasping the concept, indicating the complexity of the topic and the importance of thorough comprehension in programming and data analysis.
user366312
Gold Member
Messages
88
Reaction score
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
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
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
What percentage of programmers have learned to touch type? Have you? Do you think it's important, not just for programming, but for more-than-casual computer users generally? ChatGPT didn't have much on it ("Research indicates that less than 20% of people can touch type fluently, with many relying on the hunt-and-peck method for typing ."). 'Hunt-and-peck method' made me smile. It added, "For programmers, touch typing is a valuable skill that can enhance speed, accuracy, and focus. While...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top