0

What is incorrect about the following code?

TotalCnt<- sum(subset(Dataset,Group=="Test")$Fall_2016_Fall,na.rm=TRUE)

It shows up as 0L.

I think the following code is working though:

TotalMN <- mean(subset(Dataset,Group=="Test")$Fall_2016_Fall,na.rm=TRUE)

Maybe it is a matter of rm = TRUE should not be in the summation?

Also, I will next be subsetting by two conditions moving forward, so I would place & after my Group == "Test"? So I would say something like the following:

TotalCnt<- sum(subset(Dataset,Group=="Test"&Group2=="XYZ")$Fall_2016_Fall,na.rm=TRUE)

Would that work?

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
Zach
  • 37
  • 8
  • 2
    Without a reproducible example, it is hard to say why your code returns 0. Please read [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269/4996248) – John Coleman Aug 24 '18 at 16:24
  • 1
    Please edit **the question** with the output of `dput(Dataset)` or if it's too big `dput(head(Dataset, 20))`. As for the code it seems right. And yes, you would put the conjunction `&` right there. – Rui Barradas Aug 24 '18 at 16:25
  • Thank you to everyone for the input - it turns out that I was using an incorrect variable. It is quite good to know that my code was OK though. Under these circumstances should I remove the post, or may I leave it up as it also has great advice about how to properly frame the question with reproducible examples & dput()? – Zach Aug 24 '18 at 21:00

0 Answers0