Correction of R error with NAs