Subset Data Frame Rows by Logical Condition in R (5 Examples) | subset & filter Functions in RStudio

Описание к видео Subset Data Frame Rows by Logical Condition in R (5 Examples) | subset & filter Functions in RStudio

How to filter rows of a data frame or tibble by logical condition in the R programming language. More information: https://statisticsglobe.com/filter-da...
R code of this tutorial:


data <- data.frame(x1 = c(3, 7, 1, 8, 5), # Create example data
x2 = letters[1:5],
group = c("g1", "g2", "g1", "g3", "g1"))

##### Example 1
data[data$group == "g1", ] # Subset rows with ==

##### Example 2
data[data$group != "g1", ] # Subset rows with !=

##### Example 3
data[data$group %in% c("g1", "g3"), ] # Subset rows with %in%

##### Example 4
subset(data, group == "g1") # Apply subset function

##### Example 5
install.packages("dplyr") # Install dplyr package
library("dplyr") # Load dplyr package
filter(data, group == "g1") # Apply filter function

Комментарии

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