KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have the following data.table (DT): DT <- data.table(V1 = 1:3, V2 = 4:6, V3 = 7:9) I would like to select a subset of the variables programmatically (dynamically), by using an object where the relevant variable names are stored. For example, I want to select the two columns "V1" and "V3" stored in a variable "keep" keep <- c("V1", "V3") If we were to select the "keep" columns from a data.frame, the following would work: DT[keep] Unfortunately, this is not working when this is a data.table. I thought the data.frame and data.table are identical with this kind of behavior, but apperently they aren't. Anybody able to advise on the correct syntax?
Tags (comma-separated)
Save Edits
Cancel