Browsing resource, all submissions are temporary.
Note: You should be able to answer almost all questions by typing the commands in R. It is recommended that you first figure out the answer and then test it by typing the commands in R. Always check your answers by typing the R commands first before submitting them.
a. Suppose I type x <- 10:pi in R. Use the 'class()' function to determine the class of 'x'. character logical matrix integer numeric
x <- 10:pi
b. What is the class of the object defined by the expression x <- c("abcd", 1:19, TRUE, 2.34:15.67) ? logical matrix character integer numeric
x <- c("abcd", 1:19, TRUE, 2.34:15.67)
c. What happens if I type as.numeric(c(1:4,"11a",FALSE,9)) ? R refuses to carry out the coercion and throws an error message. All objects are coerced to numeric. The result is 1 2 3 4 1 0 9. 1:4 are coerced to numeric; 9, "11a", and FALSE remain unchanged. The result is a list containing the mixture of numeric, character and logical objects. It returns 1 2 3 4 NA NA 9 and a warning message is issued. All objects are coerced to numeric. The result is 1 2 3 4 11 0 9.
as.numeric(c(1:4,"11a",FALSE,9))
d. What happens if I type as.numeric(c(1:4,11,FALSE,9)) ? All objects are coerced to numeric. The result is 1 2 3 4 11 0 9. 1:4 are coerced to numeric; 9, 11, and FALSE remain unchanged. The result is a list containing the mixture of numeric and logical objects. All objects are coerced to numeric. The result is 1 2 3 4 1 0 9. R refuses to carry out the coercion and throws an error message. It returns 1 2 3 4 11 NA 9 and a warning message is issued.
as.numeric(c(1:4,11,FALSE,9))