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 := .)
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.
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.
(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 := .)