I have the following dataframe:
class outcome count total
A TP 5 20
A FP 5 20
A TN 5 20
A FN 5 20
B TP 10 40
B FP 10 40
B TN 10 40
B FN 10 40
Where I essentially want this in so called wide format i.e.
type TP FP TN FN total
A 5 5 5 5 20
B 10 10 10 10 40
I can almost get there by doing:
> dcast(test,test$outcome ~ test$class)
Using class...outcome...count....total as value column: use value.var to override.
. A FN 5 20 A FP 5 20 A TN 5 20 A TP 5 20
1 . A FN 5 20 A FP 5 20 A TN 5 20 A TP 5 20
B FN 10 40 B FP 10 40 B TN 10 40 B TP 10 40
1 B FN 10 40 B FP 10 40 B TN 10 40 B TP 10 40
where I now have a column for each outcome type, but I have missing column names, duplicate rows and my wanted column headers (TP,FP,TN,FN) as column values...still.
So also quite far off.
Is this even possible with dcast?