Let's say I want to create a column in the data.table in which the value in each row is equal to the standard deviations of the values in three other cells on the same row. For example, if I do
DT <- data.table(a = 1:4, b = c(5, 7, 9, 11), c = c(13, 16, 19, 22), d = c(25, 29, 33, 37))
DT
a b c d
1: 1 5 13 25
2: 2 7 16 29
3: 3 9 19 33
4: 4 11 22 37
and I would like to add a column that contains the standard deviation a, b and d for each row, for example:
a b c d abdSD
1: 1 5 13 23 12.86
2: 2 7 16 27 14.36
3: 3 9 19 31 15.87
4: 4 11 22 35 17.39
I could, of course, write a for-loop or use the apply function to compute this. Unfortunately, what I really want to do needs to be applied to millions of lines, it is not as simple as calculating the standard deviation, and it needs to be completed in a split second, so I really need a vector solution. I want to write something like
DT[, abdSD := sd(c(a, b, d))]
, , . - data.table, , ? . @Arun