r语言用filter删选出iris数据集中species是setosa和versicolor的样本
假设iris数据集已经被导入为一个名为iris的数据框,可以使用以下代码来用filter筛选出species为setosa和versicolor的样本:
library(dplyr)
iris_filtered <- iris %>%
filter(species == "setosa" | species == "versicolor")
在上述代码中,我们使用了dplyr包中的filter函数来筛选出species为setosa或versicolor的样本,并将结果存储在一个名为iris_filtered的新数据框中。注意,我们使用了逻辑运算符“|”来组合两个筛选条件。
原文地址: https://www.cveoy.top/t/topic/gAfe 著作权归作者所有。请勿转载和采集!