基本运算
R 中 character 是可以比较大小的。
R uses the alphabet to sort character strings.
首字母在后面的大。
大写字母在前, 小写字母在后。
> "Hello" > "Good"
[1] TRUE
> TRUE > FALSE
[1] TRUE
logic operator
1. 元素
and or not
& | !
2. 向量
> c(TRUE, TRUE, FALSE) & c(TRUE, FALSE, FALSE)
[1] TRUE FALSE FALSE
> c(TRUE, TRUE, FALSE) | c(TRUE, FALSE, FALSE)
[1] TRUE TRUE FALSE
> !c(TRUE, TRUE, FALSE)
[1] FALSE FALSE TRUE
&& double ampersand operation
|| double vertical bar
only examines the first element of each vector.
> c(TRUE, TRUE, FALSE) && c(TRUE, FALSE, FALSE)
[1] TRUE
You’ll need to use the && sign here. This causes the evaluation of the condition to halt as soon as the result of the condition is known; if logs[[i]]$success is TRUE, it’s certain that the condition will be FALSE, so the next comparison is not evaluated anymore.
if (logs[[i]]$success == FALSE && logs[[i]]$details$location == "waste")