EXERCISE
TOPIC: MISSING VALUES
Questions
1.
In R, what is represented by NA?
It stands for not available and represents missing values in a data set. 2.
Write the output for the code:
x<- c(NA, 3, 4, NA, NA, NA) is.na(x)
TRUE FALSE FALSE TRUE TRUE TRUE
3.
Write the output for the code:
x<- c(NA, 3, 4, NA, NA, 0 / 0, 0 / 0) is.na(x)
TRUE FALSE FALSE TRUE TRUE TRUE TRUE
4.
What does NaN stand for?
"NaN" stands for "Not a Number." It is a special value used to represent undefined or unrepresentable numerical results.
5.
What does Inf stand for? "Inf" stands for infinity. It is used to represent positive infinity in mathematical operations.
6.
Given variable m with vector m <- c(18, NA, 25, 1, NA), what is the length of this vector? Were the NA values counted?
The vector m <- c(18, NA, 25, 1, NA) in R has a length of 5 elements. The length is determined by the number of elements in the vector. Yes, the NA values were counted in the length of the vector.
7.
If x <- c(NA, 3, 14, NA, 33, 17, NA, 41), write some R code that will replace all occurrences of NA with the number 12.
x <- c(18, NA, 25, 1, NA)
x[is.na(x)] <- 0
x
TOPIC: SUBSETTING VECTORS
Questions
1.
For the given vector x <- c(-1.24, 3.18, -24, -1, 2), what will x[x>0] return?
A vector of all NAs
A vector of all the positive elements of x
A vector of TRUEs and FALSEs
A vector of all the negative elements of x
A vector of length 0
Answer: A vector of all the positive elements of x