I have a data frame
DF <- data.frame(y1=c("AG","AG","AI","AI","AG","AI"),
y0=c(2,2,1,1,2,1),
y3=c(1994,1996,1997,1999,1994,1994),y4=c("AA","FB","AA","EB","AA","EB"),
mw3wuus=c(26,34,22,21,65,78),
Country_true=c("Antigua and Barbuda","Antigua and Barbuda","Anguilla","Anguilla","Antigua and Barbuda","Anguilla"))
DF
y1 y0 y3 y4 mw3wuus Country_true
1 AG 2 1994 AA 26 Antigua and Barbuda
2 AG 2 1996 FB 34 Antigua and Barbuda
3 AI 1 1997 AA 22 Anguilla
4 AI 1 1999 EB 21 Anguilla
5 AG 2 1994 AA 65 Antigua and Barbuda
6 AI 1 1994 EB 78 Anguilla
And I'm trying to create a new column with a mean variable based on the fact that the other columns are equal
For instance, in the example, everything must be the same but rows 5 and 1, for which I need to calculate the mean of mw3wuus
, as they have the same values for y1
, y0
, y3
, and y4
.