Remove Data Frame Columns by Name in R (6 Examples) | Drop Variable | subset, within, select & setDT

Описание к видео Remove Data Frame Columns by Name in R (6 Examples) | Drop Variable | subset, within, select & setDT

How to drop the variable of a data frame by its name in the R programming language. More details: https://statisticsglobe.com/r-remove-...
R code of this video:

data <- data.frame(x1 = 1:5, # Create example data
x2 = 6:10,
x3 = letters[1:5],
x4 = letters[6:10])

data1 <- data[ , ! names(data) %in% c("x1", "x3")] # Apply %in%-operator

data2 <- data[ , names(data) %in% c("x2", "x4")] # Keep certain variables

data3 <- subset(data, select = - c(x1, x3)) # Apply subset function

data4 <- within(data, rm(x1, x3)) # Apply within function

install.packages("dplyr") # Install dplyr package
library("dplyr") # Load dplyr

data5 <- select(data, - c(x1, x3)) # Apply select function

install.packages("data.table") # Install & load data.table package
library("data.table")

data6 <- data
setDT(data6)[ , c("x1", "x3") := NULL] # Using := NULL

class(data6) # Check class of data

Follow me on Social Media:
Facebook:   / statisticsglobecom  
Patreon:   / statisticsglobe  
Pinterest: https://www.pinterest.de/JoachimSchork
Reddit:   / joachimschork  
Twitter:   / joachimschork  

Комментарии

Информация по комментариям в разработке