Question 1 The objective of this question is to help your understanding of the difference between character vectors and factors. Recall the type casting functions as .logical(), as.numeric(), and as character(), which allow us to coerce (or cast) a vector into one of a different mode. Consider the following commands: char <- c("2", "1", "O") num <- 0:2 charnum <- data.frame(char, num, stringsAsFactors = TRUE) (a) Apply as.numeric() to char and to charnum$char. Explain why there is a difference in the results.
(b) Use the type casting functions to coerce charnum$char into a numeric vector that is identical to as. numeric(char).
Question 1 The objective of this question is to help your understanding of the difference between character vectors and
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am