I want to calculate means over several columns for each row in my dataframe containing missing values, and place results in a new column called \'means.\' Here\'s my datafra
It is simple to accomplish in base R as well:
cbind(df, "means"=rowMeans(df, na.rm=TRUE))
A B C means
1 3 0 9 4.000000
2 4 6 NA 5.000000
3 5 8 1 4.666667
The rowMeans
performs the calculation.and allows for the na.rm argument to skip missing values, while cbind
allows you to bind the mean and whatever name you want to the the data.frame, df.