All,
Finding some inconsistent behaviors in how data.table deals with variable
assignment depending upon whether a $ or [[ ]] is used.
I'm using data.table 1.7.4
require(data.table)
### Using $
tmp.dt <- data.table(X=1:5)
tmp.dt$Y <- factor(1, levels=1:2, labels=c("VALID_CASE", "INVALID_CASE"))
> tmp.dt
X Y
[1,] 1 1
[2,] 2 1
[3,] 3 1
[4,] 4 1
[5,] 5 1
> sapply(tmp.dt, class)
X Y
"integer" "integer"
### Using [[
tmp.dt <- data.table(X=1:5)
tmp.dt[["Y"]] <- factor(1, levels=1:2, labels=c("VALID_CASE", "INVALID_CASE"))
> tmp.dt
X Y
[1,] 1 VALID_CASE
[2,] 2 VALID_CASE
[3,] 3 VALID_CASE
[4,] 4 VALID_CASE
[5,] 5 VALID_CASE
> sapply(tmp.dt, class)
X Y
"integer" "factor"
Thoughts,
Damian
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help