Example
require(data.table)
d <- data.table(a=sample(1:10,100,replace=T))
dcast(d[,.N,a],~a,value.var="N")
The above dcast returns the following message
Error in check_formula(formula, names(data), valnames) : Invalid formula. Cast formula should be of the form LHS ~ RHS, for e.g., a + b ~ c.
The formula has to be written as .~a
or ""~a
. Then the output looks like this
. 1 2 3 4 5 6 7 8 9 10
1: . 11 13 12 9 13 9 10 6 9 8
Is there a way of writing the formula so that the .
is not written out? I realize I can filter that out using [,-c(1),with=F]
.