keepdrop {lazy.tools} | R Documentation |
Keep or Drop the variables in the data frame
keepdrop(df, keep = NULL, drop = NULL)
df |
The data frame whose variables are to be kept/dropped. |
keep |
A vector consisting of the names of the variables to keep |
drop |
A vector consisting of the names of the variables to drop |
This functin first expands the abbreviated variable list by varlst function.
Then, it creats a data frame with the variables in the keep list.
Finally, it drops those variable in the drop list.
A data frame
df <- as.data.frame(demomat(5,7))
names(df) <- c("x1","x2","x3","a","s","m","i")
keepdrop( df, keep=c("x1", "a", "x3") )
keepdrop( df, keep="x1 a x3" )
keepdrop( df, keep="x1-x3 m" )
keepdrop( df, keep="x1--m" )
keepdrop( df, drop=c("x1", "a", "x3") )
keepdrop( df, drop="x1 a x3" )
keepdrop( df, drop="x1-x3 m" )
keepdrop( df, drop="x1--m" )