I have a data.table in R thus:
my.dt <- data.table(x=seq(1:5),y=(c(TRUE, TRUE, FALSE, FALSE, FALSE)))
I want to extract a single value, or a vector of values from this:
boolean.vector <- my.dt[x<4,"y",with=FALSE]
boolean.value <- my.dt[x<2,"y",with=FALSE]
However, these return values are still of class data.table. As such, I cannot, for example, do the following:
> if(boolean.value) { print("Hello") }
Erro em if (boolean.value) { : argumento não é interpretável como lógico
# (Error in if (boolean.value) { : argument cannot be interpreted as logical)
How can I retrieve the raw values so I can use them in this manner?
Instead of
I would just do one of:
In base R
[[doesn’t copy the vector (it’s copy-on-change), so this is very efficient and there isn’t any need to usedata.tablesyntax for this.