Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Can't assign to column" error when converting factor columns to lists. #936

Closed
richierocks opened this issue Nov 9, 2014 · 1 comment
Closed
Assignees
Labels
Milestone

Comments

@richierocks
Copy link

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, " ")]
@arunsrinivasan
Copy link
Member

@richierocks, thanks!

@arunsrinivasan arunsrinivasan self-assigned this Jan 28, 2015
@arunsrinivasan arunsrinivasan added this to the v1.9.6 milestone Jan 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants