View source: R/remove_ifall_cols.R
remove_ifall_cols | R Documentation |
For a data.frame, drop all columns that satisfy a condition or set of conditions
remove_ifall_cols( df, ifallwhat = NULL, factor_as_chr = TRUE, drop_all_NA = TRUE )
df |
A data.frame (or data.table) |
ifallwhat |
A vector of value(s) to test for. |
factor_as_chr |
If ifallwhat is of class |
drop_all_NA |
Should columns that are all NA be dropped? Defaults to |
A data.frame
, or a data.table
if this was passed to df, with
all columns that match the requirements within ifallwhat removed. If no columns
in df met the criteria requested, then the input is returned without modification.
This function will coerce the input data.frame into a data.table via
as.data.table
as an intermediate step. If a data.frame is detected
as input, setDF
is used for output coercion.
my_df <- data.frame( A = 1:3L, B = rep(numeric(3), 3), C = rep("", 3), D = rep(NA_real_, 3), stringsAsFactors = FALSE ) my_df_1 <- remove_ifall_cols(my_df, numeric(3)) my_df_2 <- remove_ifall_cols(my_df, numeric(3), drop_all_NA = FALSE) remove_ifall_cols(my_df, c(""), drop_all_NA = FALSE) remove_ifall_cols(my_df, c(1:3)) remove_ifall_cols(my_df, c(1:3), drop_all_NA = FALSE) remove_ifall_cols(my_df, as.numeric(1:3), drop_all_NA = FALSE) # does nothing
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.