Help with finding mean of 2 variables/does order matter

Hi! I am new to R Studio...So first, I created a new variable, "school", which works. There's a variety of educational attainment I grouped 3 different types of college degrees to just create the category/subset "degree"(variable -> school=="4+") the 2nd other variable is cognitive difficulty, which is dichotomous, (variable -> diffrem==1)

degree <-subset(data, school=="4+")
cogn <- subset(data, diffrem==1)

Next, I found the average/mean of people in the sample with college degrees and I found the mean of people in the sample that have a cognitive difficulty. I'm trying to find the mean of people in the sample with a college degree AND a cognitive difficulty. I'll paste the 2 codes I brainstormed (they both ran but gave me very different numbers)...I'm having trouble with the "order" of the code and what comes before and after the $ .

mean_cognxdegree <- mean(cogn $ school=="4+")  

mean_cognxdegree2 <- mean(degree $ diffrem==1)       
mean(subset(mtcars, cyl == 6 & gear == 4)$mpg)
#> [1] 19.75

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.