example R dataframe:
n = c(2, 3, 5)
s = c("aa", "bb", "cc")
b = c(TRUE, FALSE, TRUE)
df = data.frame(n, s, b)
I can easily subset columns in a dataframe like this:
df.smaller <- df[c(1,2)]
n s
1 2 aa
2 3 bb
3 5 cc
Very handy!
However, with datatable (and I thought it is easier with datatable) I have not found such a quick way to do the same. How can I quick and easy do the same to a datatable?
dt = data.table(df)
dt.smaller <- dt[c(1,2)]
n s b
1: 2 aa TRUE
2: 3 bb FALSE
will return me the first two rows. Probably it is just a comma or something I have to change, but I can't figure it out.