I have a data.frame that looks like this
df <-data.frame(Day=c(0,0,0,1,1,1),type=c("tr1","tr2","ctrl","tr1","tr2","ctrl"),
mean=c(0.211,0203,0.199,0.119,0.001,0.254),
sd=c(0.07,0.141,0.096, 0.0848, 0.0006, 0.0474))
Day type mean sd
1 0 tr1 0.211 0.0700
2 0 tr2 203.000 0.1410
3 0 ctrl 0.199 0.0960
4 1 tr1 0.119 0.0848
5 1 tr2 0.001 0.0006
6 1 ctrl 0.254 0.0474
First I want to group my dataframe based on the Day aka group_by(Day). When in each group, the sum(mean + sd) of each type (tr1, tr2) is bigger than the difference(mean - sd) of the control (ctrl) then I want in the new column (new.col), to assign the value ~yes and if not I want to assign the value ~no.
For example I want my data to look somehow like this. It does not have to look like this
Day type mean sd new.col
1 0 tr1 0.211 0.0700 yes
2 0 tr2 203.000 0.1410 yes
3 0 ctrl 0.199 0.0960 NA
4 1 tr1 0.119 0.0848 NO
5 1 tr2 0.001 0.0006 N0
6 1 ctrl 0.254 0.0474 NA