keepdrop {lazy.tools}R Documentation

Keep or Drop the variables in the data frame

Description

Keep or Drop the variables in the data frame

Usage

keepdrop(df, keep = NULL, drop = NULL)

Arguments

df

The data frame whose variables are to be kept/dropped.

keep

A vector consisting of the names of the variables to keep
or sas-like abbreviated list of variables to keep as a string.

drop

A vector consisting of the names of the variables to drop
or sas-like abbreviated list of variables to drop as a string.

Details

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.

Value

A data frame

Examples

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" )


[Package lazy.tools version 0.1.3 Index]