[datatable-help] Creating factors

Matthew Dowle mdowle at mdowle.plus.com
Mon Dec 5 23:35:31 CET 2011


Ok I see that. Please raise a bug report for this one. Thanks.

On Sun, 2011-12-04 at 05:07 -0600, Damian Betebenner wrote:
> 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
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help




More information about the datatable-help mailing list