Magic data.table that resists subset

My colleague sent the following data.table

(version 1.9.4 from CRAN):

w <- structure(
  list(
    type = c("current", "prior"),
    value = c(10, 20)
    ), 
  class = c("data.table", "data.frame"), 
  index = structure(integer(0), type = c(2L, 1L))
  )

      

At first, the w brush looks like a regular one data.table

:

> w
      type value
1: current    10
2:   prior    20
> w[type=='prior',]
    type value
1: prior    20

      

But for some reason it cannot be a subset of type == 'current'

:

> w[type=='current',]
Empty data.table (0 rows) of 2 cols: type,value

      

Using the function get

solves this problem:

> w[get('type')=='current',]
      type value
1: current    10

      

Like removing the index from data.table:

x <- structure(
  list(
    type = c("current", "prior"),
    value = c(10, 20)
  ), 
  class = c("data.table", "data.frame")
)
> x
      type value
1: current    10
2:   prior    20

      

What is this "index" attribute on the data.table and how can I prevent it from being created in the future? I know that my colleague did not intentionally create this index, but somehow during a union or subset operation this data.table acquired a magic property.

+3
r data.table


source to share


No one has answered this question yet

Check out similar questions:

629
data.table vs dplyr: can something do good and other do bad or bad?
497
Falling factor levels in a data subset
362
Why is '' '' better than 'subset'?
181
How to remove column by name in data.table?
154
What does .SD do to data.table in R
105
How to remove a row by reference in data.table?
44
Subset by group with data.table
44
How to optimize reading and writing to subsections of a matrix in R (possibly using data.table)
6
Would use% chin% for a subset of the character columns of the automatically indexed data.table ever gaining speed?
4
Substituting data.table in a for loop is slower and more resource intensive



All Articles
Loading...
X
Show
Funny
Dev
Pics