Question: mixed.1

mixed.1 <- c(TRUE,TRUE,FALSE,4,0,3)

mixed.1

## [1] 1 1 0 4 0 3

mixed.2 <- c(c(TRUE,TRUE,FALSE,4,0),"3")

mixed.2

## [1] "1" "1" "0" "4" "0" "3"

mixed.3 <- c(TRUE,TRUE,FALSE,4,0,"3")

mixed.3

Type Casting: The as.logical(), as.numeric(), and as.character() functions allow us to coerce (or cast) a vector into one of a different mode. For example:

as.logical(c("TRUE","FALSE","TRUE"))

## [1] TRUE FALSE TRUE

as.numeric(c("4","0","3"))

## [1] 4 0 3

as.character(c(TRUE,FALSE,TRUE))

## [1] "TRUE" "FALSE" "TRUE"

(a) Explain why as.numeric(mixed.2) and as.numeric(mixed.3) produce different results.

(b) Explain why as.logical(mixed.2) and as.logical(mixed.3) produce different results.

(c) How could you use the type casting functions to coerce mixed.2 into a meaningful logical vector?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!