Given the following data set:
df <-
data.frame (
var2kreuz = c(rep(c("AAA"), 8), rep(c("BBB"), 8)),
cohort = c(
rep(c("2012/13"), 3),
rep(c("2013/14"), 2),
rep(c("2014/15"), 3),
rep(c("2012/13"), 2),
rep(c("2013/14"), 3),
rep(c("2014/15"), 3)
),
var2use = c(
"negative",
"neutral",
"positive",
"neutral",
"positive",
"negative",
"neutral",
"positive",
"negative",
"neutral",
"negative",
"neutral",
"positive",
"negative",
"neutral",
"positive"
),
n = round(runif(8, min = 0, max = 101))
)
I now want to check for each group in var2kreuz and each cohort in cohort whether there are results for the three expressions negative, neutral and positive in var2use.
If there are no results for one or more expressions for a cohort, a row is to be added to the data set, e.g. for AAA and cohort 2013/14 or BBB and cohort 2012/13:
AAA in var2kreuz, 2013/14 in cohort , negative in var2use and 0 in n and BBB in var2kreuz, 2012/13 in cohort , positive in var2use and 0 in n.