I want to cast this data frame
ID GROUP CHAR_VALUE
A001 AAA
A001 BBB B01
A001 DDD X99
A002 AAA A50
A002 FFF FFF
A003
A004 FFF F01
...
Into an object like this:
ID AAA BBB DDD FFF ...
A001 N/A B01 X99 N/A ...
A002 A50 N/A N/A FFF
A003 N/A N/A N/A N/A
A004 N/A N/A N/A F01
...
With this statement
library(reshape)
cast(tbl, ID ~ GROUP, value = "CHAR_VALUE")
I get this binary outcome
ID AAA BBB DDD FFF ...
A001 1 1 1 0 ...
A002 1 0 0 1
A003 0 0 0 0
A004 0 0 0 1
...
Please note that i have some million records, so performance is important.
Similar question with integers: How to use cast on a data frame?
Update: Its throwing the following error:
Using CHAR_VALUE as value column.
Use the value argument to cast to override this choice Aggregation requires fun.
aggregate: length used as default Error in FUN(X[[i]], ...):
2 arguments passed to 'length' which requires 1