Using the following two R vectors, I want to extract a subset of valMe
using the boolean values in boolMe
. In addition, I would like to have two possible outputs, one where the FALSE values in boolMe
are ommited from valMe
, and one where the FALSE values are replaced by NA. Further illustration of what I want to do in code:
Input
boolMe<-c(FALSE, TRUE, TRUE, TRUE, FALSE, TRUE)
valMe<-1:6
Intended output
NA 2 3 4 NA 6
or
2 3 4 6