我正在尝试从包含某些植被类型的数据集中删除行。我想从我的未调查数据中删除那些在我的调查数据中没有找到植被类型的行。我找到了一种方法来做到这一点,但正在寻找一种单线方法。我目前正在这样做:
> setdiff(unsurveyed_1$VEGETATION, surveyed_1$VEGETATION)
它返回七种植被类型,然后我删除它们:
> unsurveyed_1 <- unsurveyed_1[!unsurveyed_1$VEGETATION == "Acer rubrum- Nyssa sylvatica saturated forest alliance",]
> unsurveyed_1 <- unsurveyed_1[!unsurveyed_1$VEGETATION == "Acer rubrum/Quercus coccinea-Acer rubrum-Vaccinium corybosum-Vaccinium palladium",]
> unsurveyed_1 <- unsurveyed_1[!unsurveyed_1$VEGETATION == "Building",]
> unsurveyed_1 <- unsurveyed_1[!unsurveyed_1$VEGETATION == "Parking Lot",]
> unsurveyed_1 <- unsurveyed_1[!unsurveyed_1$VEGETATION == "Prunus serotina",]
> unsurveyed_1 <- unsurveyed_1[!unsurveyed_1$VEGETATION == "Typha (angustifolia, latifolia) - (Schoenoplectus spp.) Eastern Herbaceous Vegetation",]
> unsurveyed_1 <- unsurveyed_1[!unsurveyed_1$VEGETATION == "Water",]
我尝试了一些不同的选项,包括到目前为止收效甚微的子集,我认为这将是我最好的选择。我也在寻找与 intersect 类似的东西,但我假设它会有类似的答案。
编辑:除了使用@Cath 提供的代码之外,我还对其进行了编辑以得到相反的结果。
> unsurveyed_2 <- unsurveyed_2[unsurveyed_2$VEGETATION %in% setdiff(unsurveyed_2$VEGETATION, surveyed_1$VEGETATION), ]