5. Suppose you have the following data set with missing values: 1 2 3 4 5 NA 7 6
ID: 2947755 • Letter: 5
Question
5. Suppose you have the following data set with missing values: 1 2 3 4 5 NA 7 6 NA 5 4 3 NA 2 6 10 14 NA 4 4 4 NA 10 13 16 19 NA
Give R expressions that return a vector of the data set without missing values
Give R expressions that return a vector of the data set after replacing missing values by the last non-missing values. For example, the last non-missing value of the 1st missing is “5” so replace 1st missing by “5”.
Give R expressions that return a vector of the data set after replacing missing values randomly by selecting values randomly from a vector in (a).
Explanation / Answer
x <- c(1, 2, 3 ,4, 5, NA, 7, 6, NA, 5, 4, 3, NA, 2, 6, 10, 14, NA, 4, 4, 4, NA, 10, 13, 16, 19, NA)
Give R expressions that return a vector of the data set without missing values:
x[!is.na(x)]
Give R expressions that return a vector of the data set after replacing missing values by the last non-missing values. For example, the last non-missing value of the 1st missing is “5” so replace 1st missing by “5”.
x[is.na(x)] <- x[which(is.na(x))-1]
Give R expressions that return a vector of the data set after replacing missing values randomly by selecting values randomly from a vector in (a).
x[is.na(x)] <- x[sample(x)]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.