I have 2 vectors and single a number.
a <- rnorm(40,10,4)
d <- rep(0,length(a)
filling_limit <- 8
Now, I want a 40*1 boolean vector (has.room) giving me info if the 2 conditions are satisfied:
has.room <- a > 0 && d < filling_limit
instead of returning a vector with 40 times TRUE I get just a single TRUE.
What’s the reason for this? If you are wondering about the zero vector: This thing is part of a loop and d will change within time. Thanks!
From the help page for logical operators:
&and&&indicate logical AND and|and||indicate logical OR. The shorter form performs elementwise comparisons in much the same way as arithmetic operators. The longer form evaluates left to right examining only the first element of each vector. Evaluation proceeds only until the result is determined.