any()函数检查两个TRUE而不是一个 [英] any() function check for two TRUE instead of one

查看:47
本文介绍了any()函数检查两个TRUE而不是一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R的 any()函数检查是否:给定一组逻辑向量,至少其中一个值是true?"

The any() function from base R checks whether: "Given a set of logical vectors, is at least one of the values true?"

有没有一种方法可以使用 any()函数,但是可以检查至少两个值是否正确,而不仅仅是一个?如果没有,还有其他功能可以执行这样的事情吗?

Is there a way to use the any() function, but have it check whether at least TWO of the values are true instead of just one? If not, is there another function with which I could perform something like this?

推荐答案

我们可以使用

sum(v1) >= 2

如果有多个向量,则可以

If there are multiple vectors, either do

rowSums(cbind(v1, v2, v3, ... , vn)) >=2

Reduce(`+`, list(v1, v2, ..., vn)) >=2

这篇关于any()函数检查两个TRUE而不是一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆