7. The na_example vector represents a series of counts. You can
quickly examine the object using:
library(dslabs)
data("na_example")
str(na_example)
#> int [1:1000] 2 1 3 2 1 3 1 4 3 2 ...
However, when we compute the average with the function mean, we obtain
an NA:
mean(na_example)
#> [1] NA
The is.na function returns a logical vector that tells us which
entries are NA. Assign this logical vector to an object called ind
and determine how many NAs does na_example have. Store your anwser
in na_count.
Hint: you can use the sum function to count the number of occurences of TRUE in a logical vector.
The TRUE values will be counted as 1 and the FALSE values as 0.
8. Now compute the average again, but only for the entries that are not
NA. Store the average in vector_mean.
Hint: you can subset a vector using a logical vector as index vector[logical].
Hint: remember the ! operator.