I want to group by on "col1", "col2" and get the mean of col3
newData
id col1 col2 col3 col4 col5
1 200 2000 150 151 NA
2 200 2000 250 160 "tim"
3 201 2000 300 189 NA
4 201 2000 400 182 NA
I want my output to be
id col1 col2 col3 col4 col5
1 200 2000 200 151 NA
2 201 2000 350 189 NA
aggdata <-aggregate(newData,
by=list(newData$col1,newData$col2),
FUN=mean, na.rm=TRUE)
this gives me the mean of all variables which I do not want.