NA
The na_example
dataset represents a series of counts. It is included in the dslabs package. You can quickly examine the object using
library(dslabs)
data(na_example)
str(na_example)
However, when we compute the average we obtain an NA
. You can see this by typing
mean(na_example)
This exercise is part of the course
Data Science R Basics
Exercise instructions
- The
is.na
returns a logical vector that tells us which entries areNA
. Assign the logical vector that is returned byis.na(na_example)
to an object calledind
. - Determine how many
NA
sna_example
has, using thesum
command.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Using new dataset
library(dslabs)
data(na_example)
# Checking the structure
str(na_example)
# Find out the mean of the entire dataset
mean(na_example)
# Use is.na to create a logical index ind that tells which entries are NA
# Determine how many NA ind has using the sum function