[Solved] Multiple aggregation in R with 4 parameters
You could try something like this in data.table data <- data.table(yourdataframe) bar <- data[,.N,by=y] foo <- data[x==1 & z==1,list(mean.t=mean(t,na.rm=T),median.t=median(t,na.rm=T)),by=y] merge(bar[,list(y)],foo,by=”y”,all.x=T) y mean.t median.t 1: 1 12.5 12.5 2: 2 NA NA 3: 3 NA NA 4: 4 NA NA You probably could do the same in aggregate, but I am not sure you can do … Read more