I'm trying to convert a data.table to a matrix in R. The data.table looks like this
id timeBin vel
1 NA value
1 10 value
1 20 value
1 30 value
2 20 value
2 30 value
2 40 value
2 50 value
2 60 value
2 70 value
2 80 value
3 30 value
3 50 value
3 60 value
I'm trying to make a heatplot of velocities ("value", which could be any value). The velocities are not recorded for each "id" in the same way, so that there are occuring timespans in differing sequence ("timeBin"). The Matrix' number of columns should be max(dt$id), and the number of rows should include all possible values of timeBin. For missing or NA values I have to set the value = 0.
I tried to handle this problem with cast() from the reshape package, but it does not work for me. Any suggestions to solve this problem in a simple way? Thanks in advance!