Challenge - 5 Problems
Type Conversion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of type conversion with as.numeric()
What is the output of the following R code?
R Programming
x <- c("10", "20", "thirty", "40") y <- as.numeric(x) y
Attempts:
2 left
💡 Hint
as.numeric() converts strings to numbers but returns NA for non-numeric strings.
✗ Incorrect
The string "thirty" cannot be converted to a number, so as.numeric() returns NA for that element.
❓ Predict Output
intermediate2:00remaining
Result of is.integer() on numeric vector
What does the following R code print?
R Programming
v <- c(1, 2, 3) is.integer(v)
Attempts:
2 left
💡 Hint
In R, numeric vectors are by default of type double, not integer.
✗ Incorrect
The vector v is numeric (double), so is.integer(v) returns FALSE.
❓ Predict Output
advanced2:00remaining
Behavior of as.character() on factor
What is the output of this R code?
R Programming
f <- factor(c("apple", "banana", "apple")) char_vec <- as.character(f) char_vec
Attempts:
2 left
💡 Hint
as.character() converts factor levels back to their string values.
✗ Incorrect
Factors store data as integers internally but as.character() returns the original strings.
❓ Predict Output
advanced2:00remaining
Output of typeof() on logical conversion
What is the output of this R code?
R Programming
x <- c(TRUE, FALSE, TRUE)
t <- as.integer(x)
t
typeof(t)Attempts:
2 left
💡 Hint
TRUE converts to 1 and FALSE to 0 when cast to integer.
✗ Incorrect
as.integer converts logical TRUE/FALSE to 1/0 and typeof confirms the vector type is integer.
❓ Predict Output
expert3:00remaining
Result of coercion in mixed-type vector
What is the output of this R code?
R Programming
v <- c(1L, 2.5, TRUE, "4") v typeof(v)
Attempts:
2 left
💡 Hint
When combining different types, R coerces all elements to the most flexible type.
✗ Incorrect
Because of the character "4", all elements become character strings.