Understand how a logical vector can be used as an address So
Understand how a logical vector can be used as an address.
Solution
In R language we can also use logical vectors as parameter for the index function.
When it is used a vector with values that make logical vector true are obtained (i.e whether logical condition is satisfied or not)
Example :
> x <- c(4, 5, 1, NA, 2)
> x[x > 3]
[1] 4 5 NA
Here x>3 is a logical vector
Example 2
> a <- c(1,2,3,4,5)
> b <- c(TRUE,FALSE,FALSE,TRUE,FALSE)
> a[b]
[1] 1 4
> max(a[b])
[1] 4
> sum(a[b])
[1] 5
Here b is a logical vector to address which elements of \"a\" are available
