Skip to content

zero length .SDcols #1789

@ggrothendieck

Description

@ggrothendieck

It would be nice if .SDcols could be zero length. In #1786 we discussed this code which works but a special case had to be made for the situation where there were no numeric columns.

iris.dt <- as.data.table(iris)
nums <- which(sapply(iris.dt, is.numeric))
if (length(nums)) iris.dt[, (nums) := .SD/rowMeans(.SD), .SDcols = nums]

It would be nice if .SDcols could allow the specification of no columns so that this would work even in the case that iris has no numeric columns.

iris.dt <- as.data.table(iris)
nums <- which(sapply(iris.dt, is.numeric))
iris.dt[, (nums) := .SD/rowMeans(.SD), .SDcols = nums]

(Incidentally it would also be nice if nums could be logical so that we could have nums <- sapply(iris.dt, is.numeric) . That works in .SDcols= but not on the LHS of := .)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions