Extract Certain Columns of a Data Frame in R (4 Examples) | Subset Variables by Column Name

Описание к видео Extract Certain Columns of a Data Frame in R (4 Examples) | Subset Variables by Column Name

How to get the subset of columns of a data frame. Detailed explanations can be found in this tutorial: https://statisticsglobe.com/extract-c...

R programming code on how to extract columns of a data matrix:

data <- data.frame(x1 = c(2, 1, 5, 1), # Create example data
x2 = c(7, 1, 1, 5),
x3 = c(9, 5, 4, 9),
x4 = c(3, 4, 1, 2))

data[ , c("x1", "x3")] # Subset by name

data[ , c(1, 3)] # Subset by position

subset(data, select = c("x1", "x3")) # Subset with select argument

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

data %>% select(x1, x3) # Subset with select function

Комментарии

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