Use %in% instead of foo == 'bar' | foo == 'baz'
Use sum(is.na(...)) instead of length(which(is.na(...)))