Filter Data in R with subset()
In R language, you can use the subset() function to filter data. The parameters of the subset() function include a data frame object and a logical condition, which are used to filter the data frame. For example, here is a simple example:
# 创建一个数据框
data <- data.frame(
id = 1:5,
name = c("Alice", "Bob", "Charlie", "David", "Eve"),
age = c(25, 30, 35, 40, 45)
)
# 筛选年龄大于30的数据
subset_data <- subset(data, age > 30)
print(subset_data)
Running the above code will output the data with ages over 30.
id name age
4 4 David 40
5 5 Eve 45