patt<-c(`205` = FALSE, `210` = TRUE, `16` = TRUE, `2` = FALSE)
totalobs<-0
{for (element in patt)
if (element == TRUE){
print (element)
totalobs=totalobs+sum(element)
}
print (totalobs)
}
I have a logical vector see here, of which I want to add all the values of TRUE. With the above code I am only able to add up the amount of times TRUE is present in this vector, rather than the numbers that are above each TRUE value. I am quite new to R, how would I solve this?