Row wise mean – row mean in R dataframe

Row wise mean of the dataframe in R is calculated using rowMeans()  function. Lets see how to compute row mean in R

First lets create the dataframe


df1 = data.frame( Name = c('George','Andrea', 'Micheal','Maggie','Ravi','Xien','Jalpa'), 
 Mathematics1_score=c(62,47,55,74,32,77,86),
 Mathematics2_score=c(45,78,44,89,66,49,72),
 Science_score=c(56,52,45,88,33,90,47))

df1 will be

Row wise mean in R dataframe Row mean in R 1

 

Row wise mean in R dataframe:

Let’s calculate the row wise mean as shown below


df1$Avg_score = rowMeans(df1[,c(2,3,4)])
df1

So the resultant dataframe will be

Row wise mean in R dataframe Row mean in R 2