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 <- c(1,3,5) in R. Use the 'class()' function to determine the class of 'x'. logical integer character numeric matrix
x <- c(1,3,5)
b. What is the class of the object defined by the expression x <- c("abcd", 1:19, TRUE, 2.34:15.67) ? character matrix integer numeric logical
x <- c("abcd", 1:19, TRUE, 2.34:15.67)
c. What happens if I type as.numeric(c(1:4,"11a",FALSE,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. All objects are coerced to numeric. The result is 1 2 3 4 11 0 9. All objects are coerced to numeric. The result is 1 2 3 4 1 0 9. It returns 1 2 3 4 NA NA 9 and a warning message is issued. R refuses to carry out the coercion and throws an error message.
as.numeric(c(1:4,"11a",FALSE,9))
d. What happens if I type as.numeric(c(1:4,11,FALSE,9)) ? It returns 1 2 3 4 11 NA 9 and a warning message is issued. 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. 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 11 0 9.
as.numeric(c(1:4,11,FALSE,9))