I assume you use data.table
. Then you can use setdiff
as in the following example:
> days = data.table(a = 1:2, b = 3:4, id = c(1, 1))
>
> days <- days[, lapply(X = .SD, FUN = identity),
+ .SDcols = setdiff(colnames(days), "id")]
> days
a b
1: 1 3
2: 2 4
or just drop id
to start with
> days = data.table(a = 1:2, b = 3:4, id = c(1, 1))
> days <- days[, id := NULL][, lapply(X = .SD, FUN = identity)]
> days
a b
1: 1 3
2: 2 4
If you want to keep the id
column then this should do (I added this after seeing your comment)
> set.seed(23812349)
> days = data.table(a = rnorm(2), b = rnorm(2), id = c(1, 1))
> days
a b id
1: -1.461587 0.2130853 1
2: 1.062314 0.8523587 1
>
> .cols <- setdiff(colnames(days), "id")
> days[, (.cols) := lapply(.SD, round, digits = 1), .SDcols = .cols]
> days
a b id
1: -1.5 0.2 1
2: 1.1 0.9 1