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

.SDcols with logical vector · Issue #4115 · Rdatatable/data.table · GitHub

.SDcols with logical vector #4115

Description

In ?data.table about .SDcols argument:

May be character column names or numeric positions.

However, it seems like also a logical vector is possible, e.g.

d <- data.table(x = 1, y = "a")
d[ , .SD, .SDcols = sapply(d, is.numeric)]
#    x
# 1: 1

If selecting columns with a logical vector in .SDcols is intended to work, should this possibility be added to the help text?

Please also note two differences with j in this regard:

(1) Using a logical vector longer than the number of columns errors in j, but not in .SDcols

d[ , c(TRUE, TRUE, TRUE)]
# Error in `[.data.table`(d, , c(TRUE, TRUE, TRUE)) : 
#  Item 3 of j is 3 which is outside the column number range [1,ncol=2]

d[ , .SD, .SDcols = c(TRUE, TRUE, TRUE)]
#    x y
# 1: 1 a

(2) If a logical vector with length k < ncol(x) is passed to j, it will be filled to length ncol(x) with FALSE. In .SDcols, the logical vector is recycled.

d[ , TRUE]
#    x
# 1: 1

d[ , .SD, .SDcols = TRUE]
#    x y
# 1: 1 a

data.table 1.12.9 IN DEVELOPMENT built 2019-12-13 23:32:57 UTC

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL