# c integer, fill numeric: no need to specify fill = 0L
DT = data.table(a = c(1L, 1L, 2L), b = c(1L, 2L, 2L), c = c(1L, 1L, 1L))
dcast(DT, a ~ b, value.var = 'c', fill = 0)[ , sapply(.SD, class)]
# a 1 2
# "integer" "integer" "integer"
# c numeric, fill integer: no attempt to convert c's output to integer due to fill's class
DT = data.table(a = c(1L, 1L, 2L), b = c(1L, 2L, 2L), c = c(1.1, 1.2, 1.3))
dcast(DT, a ~ b, value.var = 'c', fill = 0L)[ , sapply(.SD, class)]
# a 1 2
# "integer" "numeric" "numeric"
# c numeric, fill character: it seems as.numeric('a') causes the failed conversion warning
DT = data.table(a = c(1L, 1L, 2L), b = c(1L, 2L, 2L), c = c(1.1, 1.2, 1.3))
dcast(DT, a ~ b, value.var = 'c', fill = 'a')[ , sapply(.SD, class)]
# a 1 2
# "integer" "numeric" "numeric"
It appears
dcastwill attempt to convert the value offillto match that ofvalue.var; I think this is right/probably expected, but should probably be added to?dcast.data.tableanyway (was wondering whether I needed to sayfill = 0Lor wouldfill = 0be fine to getintegeroutput):