-1

This is my dataset and I want to find the mean of females in math scores. This was my code:

mean(Dataset_A[Dataset_A$gender=="female", "math score"])

Warning in mean.default(Dataset_A[Dataset_A$gender == "female", "math score"]) :
argument is not numeric or logical: returning NA [1] NA

user438383
  • 5,716
  • 8
  • 28
  • 43
dan
  • 1
  • 2
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Please do not post pictures of data. Share data in a format that can be copy/pasted into R. – MrFlick Oct 11 '21 at 16:32
  • Please provide enough code so others can better understand or reproduce the problem. – Community Oct 13 '21 at 13:10

1 Answers1

1

It is possible that the data is a tibble, thus, it wouldn't drop the dimensions when we specify the row/column index. We may extract the column "mean score" as a vector based on the logical vector and get the mean

mean(Dataset_A[["mean score"]][Dataset_A$gender=="female"], na.rm = TRUE)
akrun
  • 874,273
  • 37
  • 540
  • 662