I have the following data.table as an example
df = data.table(id = c(1, 2, 3), val=c("['hello', 'world']", "['hi']", "['so', 'there']"))
I want to split the list like object into separate rows with the id repeated. So the expected data.table I want is the following
df2 = data.table(id = c(1, 1, 2, 3, 3), val=c("hello", "world", "hi", "so", "there"))
I tried the following
df[, c("test") := tstrsplit(val, ",", fixed=TRUE)]
However, I got the following error
Error in
[.data.table(df, ,:=(c("test"), tstrsplit(val, ",", fixed = TRUE))) : Supplied 2 items to be assigned to 3 items of column 'test'. If you wish to 'recycle' the RHS please use rep() to make this intent clear to readers of your code.
Could someone point out what I'm doing wrong here? Thanks in advance.
df$valor is this a list column? - mnistfixed. also you should wrap the result in a list. iedf[, .(test=tstrsplit(val, ',')), by = id]- Onyambufixedis probably preferable even if it's not needed - MichaelChiricodf$val- broccoli