I have a data frame that looks like this:
data<-data.frame(y=c(1,1,2,2,3,4,5,5),x=c(5,5,10,10,5,10,5,5))
  y  x
1 1  5
2 1  5
3 2 10
4 2 30
5 3  5
6 4 10
7 5  4
8 5  8
How can a merge those rows with same value in y column and modify the x column value to the mean of them.
I would like something like this:
  y  x
1 1  5
2 2 20
3 3  5
4 4 10
7 5  6
I'm trying:
unique(data)
But it removes the values instead of doing the mean of same rows.
 
     
     
     
    