Here is my data:
x <- rnorm(0,1, n = 6)
class <- c(1,1,1,2,2,2)
df <- cbind(x, class)
I want to calculate the mean of x by class and have them repeat for all rows (I get a new column with the means for each class repeated so that the number of rows of the data frame remain the same.