You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Converting a character column to a list works as expected:
DT <- data.table(
x = c("a", "b c", "d e f")
)
DT[, x := strsplit(x, " ")]
I thought that converting a factor would behave in the same way, but it throws an error:
DT <- data.table(
x = factor(c("a", "b c", "d e f"))
)
DT[, x := strsplit(as.character(x), " ")]
## Error in `[.data.table`(DT, , `:=`(x, strsplit(as.character(x), " "))) :
## Can't assign to column 'x' (type 'factor') a value of type 'list' (not character, factor, integer or numeric)
Assigning to a different column name works OK:
DT[, y := strsplit(as.character(x), " ")]
A workaround is possible using a two-stage conversion:
DT[, x := as.character(x)]
DT[, x := strsplit(x, " ")]
The text was updated successfully, but these errors were encountered:
Converting a character column to a list works as expected:
I thought that converting a factor would behave in the same way, but it throws an error:
Assigning to a different column name works OK:
A workaround is possible using a two-stage conversion:
The text was updated successfully, but these errors were encountered: