Drop Multiple Columns from Data Frame Using dplyr Package in R (Example) | select & one_of Functions

preview_player
Показать описание
R code of this video:

x2 = letters[1:5],
x3 = 5,
x4 = c(3, 1, 6, 3, 7))

library("dplyr") # Load dplyr

col_remove <- c("x1", "x3") # Define columns that should be dropped

data_new <- data %>% # Apply select & one_of functions
select(- one_of(col_remove))

Follow me on Social Media:
Рекомендации по теме
Комментарии
Автор

Very helpful!! as previously I used to remove columns using $ and NULL and it was a hassle really

shivamshinde
Автор

Nice! Is there any difference between 'one_of ()' and 'any_of ()' in this case?

r_rabbitrabbit
Автор

Thanks a lot! One question: my dataset has ~12K variables, so I want to make my col_remove contain only columns having less than 20 specific values. Let's say, each column has "yes" or "no", only include columns <20 yes. Please help me!

evermoreislove
Автор

data_new <- data %>%
select(- col_remove)


what if we use this code? does it matter?

AIFLIMAX
visit shbcf.ru