how to count the number of NA in r

# Step 1: Create a sample vector with NAs
sample_vector <- c(1, 2, NA, 4, NA, 6, 7, NA, 9)

# Step 2: Use the `is.na()` function to create a logical vector indicating NA values
na_logical_vector <- is.na(sample_vector)

# Step 3: Use the `sum()` function to count the number of TRUE values in the logical vector
number_of_na <- sum(na_logical_vector)

# Step 4: Print the result
print(number_of_na)