Skip to content

FR: lapply + other columns: improving automatic handling of column names #1604

@MichaelChirico

Description

@MichaelChirico
DT <- data.table(x = 1:5, y = 1:5, z = 6:10)

DT[ , c(list(x), lapply(.SD, `^`, 2)), .SDcols = c("y", "z")]
#    V1  y   z
#1:  1  1  36
#2:  2  4  49
#3:  3  9  64
#4:  4 16  81
#5:  5 25 100

Is conjugate to the approach without .SD:

DT[ , .(x, y^2, z^2)]
#    x V2  V3
#1: 1  1  36
#2: 2  4  49
#3: 3  9  64
#4: 4 16  81
#5: 5 25 100

Seems like it's clear in the first case that V1 should be named x (fixed with c(list(x=x, ...)))

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions