Here is some example data, df
:
age_group class Value
0-4 A 2
0-4 A 1
0-4 B 1
5-9 A 2
5-9 A 3
5-9 B 1
5-9 B 1
9-14 A 1
I have been attempting to create a two way summary table -something like this:
0-4 5-9 9-14
A 3 5 1
B 1 2 NA
I thought i had cracked it last night with:
tmp = with(df, tapply(Value), list(age_group, class), FUN=sum))
However when inspecting this table the numbers don't tie up with what i would expect.
Does anyone know what my tmp
table actually represents? Also how would i get my desired result?
Thanks, John