I have a data.table
that looks like this:
dt <- data.table(a = 1, b = 1, c = 1)
I need column b
to be treated as an integer vector of variable length, so I can append additional elements to it. For instance, I want to add 2
to column b
in the first row. I tried
dt[a == 1, b := c(b, 2)]
but that doesn't work. It gives me a warning:
Warning message:
In `[.data.table`(dt, a == 1, `:=`(b, c(b, 2))) :
Supplied 2 items to be assigned to 1 items of column 'b' (1 unused)
What's the right syntax for this?