NA marks missing data. Logical masks and is.na let a script select only known values.

Program

Play the script to watch the missing score get excluded before the average is computed.

missing_values.R
scores <- c(10, NA, 8)
known <- !is.na(scores)
average <- mean(scores[known])
cat(average, "\n", sep = "")
NA `NA` represents a missing value in R.
is.na `is.na(scores)` returns `TRUE` where values are missing.
logical mask A logical vector can select matching positions from another vector.