excluding column already defined numeric in list

I have a list of column types where we defined the type of column for example character type or numeric. and now i am checking the frequency of numeric values in all columns.

so here i want to apply the code below for column excluding which are already defined as integer or which are defined as character

col_list <- list(newid = as.character(),
col1 = as.integer(),
col2 = as.integer()
col3 = as.character()
col_max = as.character())
data <- data.frame(newid= c(212,132,354,222,263,235,233,263,106,135,144),
                   col1= c(1,2,2,1,4,3,2,4,0,5,0),
                   col2= c(1,1,0,3,2,4,1,0,1,3,5),
                   col3= c(1,1,0,3,2,4,1,0,1,3,5),
                   col4= c(1,1,0,3,2,4,1,0,1,3,5),
                   col_max= c("NM","mn","PA","OH","KL","AB","OT","HA","AM","LA","GA"))

data %>% summarise(across(starts_with("col") &  !ends_with("_max"), ~ sum(.x, na.rm = TRUE)))
df1 <- df %>% summarise(across(starts_with("col_") &  names(df) != ends_with("_max"), ~ sum(.x, na.rm = TRUE)))

so here it should give statistics for col2:col4 only dynamically

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.