I can't figure out how to solve this easily. I would like to create a crosstable of my value crossed by sex (and age later adding the right column)
My table below :
x>
country sex answer value
SCO ALL A 50
SCO M A 52
SCO F A 48
SCO ALL B 71
SCO M B 77
SCO F B 65
WAL ALL A 45
WAL M A 48
WAL F A 43
WAL ALL B 71
WAL M B 79
WAL F B 63
I would like to cross table to get something like this where i would later add an age variable of whatever
I've tried something like this using flextable::tabulator
tabulator(
x = x, rows = c("answer", "country"),
columns = c("sex"),
) |>
as_flextable()
and I encounter this error Error in [.data.table
(dat, , .SD, .SDcols = columns) :
Some items of .SDcols are not column names: [.tab_columns]
I've seen the crosstable function to but I can't figure out how to use it to this purpose