many missing values after using rowMeans

Dear all, I would like to ask for help.
I wanted to create subscales by taking various variables together and get the mean value like this:

#> Scale for external problems with subscales RV and AV
YSR_num$mean_S_RV <- rowMeans(subset(YSR_num, select = c("YSR_s_2", "YSR_s_26", "YSR_s_28", "YSR_s_39", "YSR_s_43", "YSR_s_63", "YSR_s_67", "YSR_s_72", "YSR_s_81", "YSR_s_82", "YSR_s_90", "YSR_s_96", "YSR_s_99", "YSR_s_101", "YSR_s_105"), na.rm=T)) # regelverletzendes Verhalten
YSR_num$mean_S_AV <- rowMeans(subset(YSR_num, select = c("YSR_s_3", "YSR_s_16", "YSR_s_19", "YSR_s_20", "YSR_s_21", "YSR_s_22", "YSR_s_23", "YSR_s_37", "YSR_s_57", "YSR_s_68", "YSR_s_86", "YSR_s_87", "YSR_s_89", "YSR_s_94", "YSR_s_95", "YSR_s_97", "YSR_s_104"), na.rm=T)) # aggressives Verhalten

Now there are many NAs in these new Coulums YSR_num$mean_S_RV and YSR_num$mean_S_AV, what doesn't really makes sense, since the variebles we selected ( c("YSR_s_2", "YSR_s_26", etc. ...)) contain only a few missings and it just seems unrealistic for having created so many now.

thats a small output:

Just for checking we tried the same in SPSS and there were no such missings, so we must have done something wrong in R but we just can't find the mistake.

If there are any NA values, the resulting mean will be NA. I think you've added the na.rm=TRUE into the wrong place. Try this:

YSR_num$mean_S_RV <- rowMeans(subset(YSR_num, select = c("YSR_s_2", "YSR_s_26", "YSR_s_28", "YSR_s_39", "YSR_s_43", "YSR_s_63", "YSR_s_67", "YSR_s_72", "YSR_s_81", "YSR_s_82", "YSR_s_90", "YSR_s_96", "YSR_s_99", "YSR_s_101", "YSR_s_105")), na.rm=TRUE) # regelverletzendes Verhalten
YSR_num$mean_S_AV <- rowMeans(subset(YSR_num, select = c("YSR_s_3", "YSR_s_16", "YSR_s_19", "YSR_s_20", "YSR_s_21", "YSR_s_22", "YSR_s_23", "YSR_s_37", "YSR_s_57", "YSR_s_68", "YSR_s_86", "YSR_s_87", "YSR_s_89", "YSR_s_94", "YSR_s_95", "YSR_s_97", "YSR_s_104")), na.rm=TRUE) # aggressives Verhalten
1 Like

omg, yes that was it! Thank you very much :slight_smile:

This topic was automatically closed 7 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.