如何解决excel countif 函数是否有 R 等效项?
我有 4 列,它们都是唯一的条形码,但是 A 列 (V1) 中的条形码可能出现在 B (V2) 或 C (V3) 或 D (V4) 列中。
A 列 (V1) 是原始条形码。
我想查看 A 列中的条形码是否出现在任何其他列中。只是一个简单的 1(是)或 0(否)。
在excel中,我会使用“countif”,然后选择cel,然后选择范围。但是我不能使用 excel 因为数据集超过一百万行。所以我使用的是我非常缺乏经验的 Rstudio。
条形码数据框称为 df.correct
。
我试过了:
df.correct$outcome <- if (df.correct$V1 == df.correct$V2) {
1} else if (df.correct$V1 == df.correct$V3) {
1} else if (df.correct$V1 == df.correct$V4) {
1} else {0}
给出:
Warning messages:
1: In if (df.correct$V1 == df.correct$V2) { :
the condition has length > 1 and only the first element will be used
2: In if (df.correct$V1 == df.correct$V3) { :
the condition has length > 1 and only the first element will be used
3: In if (df.correct$V1 == df.correct$V4) { :
the condition has length > 1 and only the first element will be used.```
它与向量有关吗?所以我在 stackoverflow 上搜索并尝试:
if (a>0){
a/sum(a)
}
else 1
}
这没有用。有人可以帮忙吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。