corrected inequality operator typo and added condition to remove NAs for loop