Hi all. From yesterday I was trying to find the conditional mean of the variable. In my case, I need two variables. One is continuous (positive), and the second one is binomial (yes=1, no=0). So, I have to find the mean of the first variable (continuous), if the second variable will equal to 1 (yes). And repeat the operation for the the same variable if the second variable is no (0). Also, I need to include na.rm = TRUE so that error didn't appear in my command line, because there are gaps in the table not filled in (NA). I have tried some commands, but they seem to be totally incorrect. Here are some of my attempts (mydata - data name, it was subsetted from the main data, because I needed only one year for all variables among all given years, x1 - continuous variable, x2 - binomial variable)
- if(mydata$x2 == 1) w <- mydata$x1
error: the condition has length > 1 and only the first element will be used
- mean(mydata[mydata$x2>0, "x1"])
Answer:  NA.
I don't know also how to integrate na.rm = TRUE argument here.
Please, help. Thanks.