FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Strange behaviours when updating by reference a factor · Issue #6886 · Rdatatable/data.table · GitHub

Strange behaviours when updating by reference a factor #6886

Description

Look below:

> library(data.table)
data.table 1.17.0 using 6 threads (see ?getDTthreads).  Latest news: r-datatable.com
> load("../Tresorit/aux_.rdata")
> aux
        seqn                        area
       <int>                      <fctr>
    1:     1     Pontevedra-Ourense-Vigo
    2:     2 Coruña-Santiago-Ferrol-Lugo
    3:     3 Coruña-Santiago-Ferrol-Lugo
    4:     4     Pontevedra-Ourense-Vigo
    5:     5     Pontevedra-Ourense-Vigo
   ---                                  
14472: 14472     Pontevedra-Ourense-Vigo
14473: 14473     Pontevedra-Ourense-Vigo
14474: 14474 Coruña-Santiago-Ferrol-Lugo
14475: 14475 Coruña-Santiago-Ferrol-Lugo
14476: 14476     Pontevedra-Ourense-Vigo
> str(aux)
Classesdata.tableand 'data.frame':  14476 obs. of  2 variables:
 $ seqn: int  1 2 3 4 5 6 7 8 9 10 ...
 $ area: Factor w/ 3 levels "","Coruña-Santiago-Ferrol-Lugo",..: 3 2 2 3 3 2 3 2 2 2 ...
 - attr(*, ".internal.selfref")=<externalptr> 
> levels(aux$area)
[1] ""                            "Coruña-Santiago-Ferrol-Lugo"
[3] "Pontevedra-Ourense-Vigo"    
> aux[area==""]
    seqn   area
   <int> <fctr>
1:  4207       
2:  6514       
> aux[seqn==6514, area := "Coruña-Santiago-Ferrol-Lugo"]
> levels(aux$area)
[1] ""                            "Coruña-Santiago-Ferrol-Lugo" "Pontevedra-Ourense-Vigo"     "Coruña-Santiago-Ferrol-Lugo"
> unique(levels(aux$area))
[1] ""                            "Coruña-Santiago-Ferrol-Lugo" "Pontevedra-Ourense-Vigo"    
> sessionInfo()
R version 4.4.2 (2024-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 26100)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    

time zone: Europe/Madrid
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] data.table_1.17.0

loaded via a namespace (and not attached):
[1] compiler_4.4.2 tools_4.4.2   

A new level appears duplicated. Why? I cannot reproduce with simpler datasets. You can download the data at https://web.tresorit.com/l/wORmA#C3_AsIeHrOjdBItVtuxxvQ (for 30 days and no more than 20 times)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL