'Summing NAs in each row in a new column

for (i in 1:nrow(survey_clean)) {
    for(j in 1:ncol(survey_clean)) {
        survey_clean$invalid_answers[i] <- sum(survey_clean$old_col == survey_clean$old_col[i], is.na = TRUE)
    }
}

By using for loop I would like to add a new column (invalid_answers) to my data frame that contains the sum of NA values in each row.

I created the code above, which create the new column, but NAs does not add up. I tried several options to sum NAs, but none of them really worked.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source