# my data set
datapasta::df_paste(head(df.summary.pre, 24))
data.frame(
treatment = c(0L,0L,0L,0L,0L,
0L,0L,0L,0L,0L,0L,0L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L),
mean = c(2080.80524668034,
1894.47583081571,1645.53080824431,1287.96860164005,
1205.21353042728,1597.5904186448,2078.47593871385,
2038.90839447562,1686.11048769961,1212.36825636599,
1460.7180845314,1771.19468546638,
2074.22014135427,1888.73851360146,1643.06264236902,
1285.04594260428,1200.89990888976,1590.37771703762,
2070.3251659508,2034.21189639464,1680.32800754938,
1205.71369537631,1453.78814278256,1766.48370098841),
sd = c(882.836084693134,
820.410642991885,689.148421405028,647.125102287398,
464.250357867045,664.65512876134,800.929236387366,
774.277294321536,730.11311283474,484.567342986466,
588.017853816504,728.384746716548,
884.555478679759,820.317713198492,692.802742555817,
640.326840907904,459.636585613027,650.083749456554,
785.85824899789,769.739885544013,732.198317691098,
483.16075014882,588.055376335814,739.676252388324),
n = c(9263L,9268L,9267L,
9268L,9268L,9268L,9268L,9268L,9268L,9268L,
9251L,9220L,30703L,30732L,30730L,30732L,30732L,
30732L,30732L,30732L,30731L,30732L,30646L,
30546L),
month = as.factor(c("1","2","3","4","5","6","7","8","9",
"10","11","12","1","2","3","4",
"5","6","7","8","9","10","11","12"))
)data.frame(
treatment = c(0L, 0L, 0L, 0L),
mean = c(2080.80524668034,1894.47583081571,
1645.53080824431,1287.96860164005),
sd = c(882.836084693134,820.410642991885,
689.148421405028,647.125102287398),
n = c(9263L, 9268L, 9267L, 9268L),
month = as.factor(c("1", "2", "3", "4"))
)
#now I want to calculate the mean difference for each month between treatment group and control group
df.2a <- df.summary.pre %>% group_by(month) %>%
summarise(tstats =
mean[treatment=1]-mean[treatment=0]
)
# this is wrong. what's the problem?