I am trying to create a summary statistics data table by looping through the columns of an existing data table. So I want to compute the summary statistics per column. My data looks something like this:
I have tried looping through the columns, however when I do this, I am not able to extract the columns as normally done in a regular data frame. I am new to the data.table package so any help would really be appreciated.
DT <- data.table(math = c(7, 9, 3, 6), physics = c(7, 7, 4, 5),
biology = c(6, 8, 7, 6))
> DT
math physics biology
1: 7 7 6
2: 9 7 8
3: 3 4 7
4: 6 5 6
and I would like to get a new data table that looks something like this:
> DT2
subject mean median min max
1: math 6.25 6.5 3 9
2: physics 5.75 6.0 4 7
3: biology 6.75 6.0 6 8