Practice 2 missing values subsetting vectors

.docx

School

University of Illinois, Urbana Champaign *

*We aren’t endorsed by this school

Course

557

Subject

Mathematics

Date

Feb 20, 2024

Type

docx

Pages

2

Uploaded by MegaRose12943

Report
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
2. Create a vector with the values {8, 4, 1, -1, 9}. Assign this to a variable y. Print the 1 st index value. Answer: y = c(8, 4, 1, -1, 9) element = y[3] element 3. Print all the values in y except for the first value Answer: y = c(8, 4, 1, -1, 9) element = y[2:5] element 4. Copy y into w. Test if both the vectors are identical. Answer: w=y y==w
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help