I am trying to learn data.table. Stuck at an early stage :) I know how to do it in R base, but not in data.table:
library(data.table)
x<-data.table(a=1:5,b=2:6,c=3:7)
x
myvars = names(x)[2:3]
First, I just want to see my data frame by referring to 'myvars' vector. It's very important for me because frequently I work with a lot of variables in 'myvars':
x[, myvars] # I understand why it's not working
x[, .(b,c)] # This is working, I understand why
x[, .(myvars)] # This is not working - why? How can I make it work?
I don't have the luxury to refer to all variable names all the time - I need to use them in a vector. Further, I want to run "table" (or any function) on each of myvars: Like this (using base):
X<-data.frame(a=1:5,b=2:6,c=3:7)
lapply(X[myvars],table)
How can I do it in data.table?
Thanks a lot!