swirl 8: Logic

10 篇文章 0 订阅

&,&& You can use the `&` operator to evaluate AND across a vector. The `&&` version of AND only evaluates the first member of a vector.

> TRUE & c(TRUE,FALSE,FALSE)
[1]  TRUE FALSE FALSE

> TRUE && c(TRUE,FALSE,FALSE)
[1] TRUE

I,II The `|` version of OR evaluates OR across an entire vector, while the `||` version of OR only evaluates the first member of a vector.

TRUE() The function isTRUE() takes one argument. If that argument evaluates to TRUE, the function will return TRUE. Otherwise, the function will return FALSE.

identical() The function identical() will return TRUE if the two R objects passed to it as arguments are identical.

xor() You should also be aware of the xor() function, which takes two arguments. The xor() function stands for exclusive OR. If one argument evaluates to TRUE and one argument evaluates to FALSE, then this function will return TRUE, otherwise it will return FALSE.

which() The which() function takes a logical vector as an argument and returns the indices of the vector that are TRUE. For example which(c(TRUE, FALSE, TRUE)) would return the vector c(1, 3).

any() and all() the functions any() and all() take logical vectors as their argument. The any() function will return TRUE if one or more of the elements in the logical vector is TRUE. The all() function will return TRUE if every element in the logical vector is TRUE.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值