r - 如何在一个数据框中找到唯一值并使用它来过滤 R 中的另一个数据框
问题描述
我有两个引用相同实验的数据框(bmdat1、plots1)。我需要从 plots1$Bucket 中找到唯一值,并使用它们通过 plots1#Bucket 中的唯一值过滤第二个数据框。
这是我尝试过的
bm1dat1 <- filter(bmdat1, bucket == as.vector(unique(plots1$Bucket)))
这返回
Warning messages:
1: In `==.default`(bucket, as.vector(unique(plots1$Bucket))) :
longer object length is not a multiple of shorter object length
2: In is.na(e1) | is.na(e2) :
longer object length is not a multiple of shorter object length
我也试过
bm1dat1 <- filter(bmdat1, bucket == unique(plots1$Bucket))
我收到了
Error in Ops.factor(bucket, unique(plots1$Bucket)) :
level sets of factors are different
解决方案
我认为您需要使用%in%
来检查左侧集合中的元素是否存在于右侧集合中(这听起来像是您正在尝试做的事情)。这应该可行,但不知道,因为我们没有您的数据样本可供使用。
bm1dat1 <- filter(bmdat1, bucket %in% unique(plots1$Bucket))
推荐阅读
- functional-programming - 在 F# 中并行柯里化多个函数
- r - 合并具有不同采样频率的数据帧
- c# - 无法投射对象匿名通用列表
- go - 仅在合并到 master 时运行任务
- python - 通过变量修改嵌套字典
- scala - 如何在元组分配中混合本地和覆盖成员
- azure-data-explorer - 如何在同一列上使用标量运算?
- javascript - 如何让 id 选择器与项目 id 连接
- java - 如何将“24cd2ec2-6674-4aa2-a761-1b0a953124ba”(字符串对象)转换为 BigDecimal
- docker - 如何将文件从一个 docker 容器复制到另一台主机上的另一个容器?