Quiz
This lesson is called Quiz, part of the R in 3 Months (Fall 2026) course. This lesson is called Quiz, part of the R in 3 Months (Fall 2026) course.
Quiz
What is the difference between as.numeric() and parse_number()?
parse_number() extracts the first number it finds, dropping any non-numeric characters before the first number and all characters after the first number. Only if no number is found for a given cell, it turns its value into NA, regardless of the variable type.
as.numeric() turns values that contain strings into NA; parse_number() extracts the first number it finds, dropping any non-numeric characters before the first number and all characters after the first number.
To see the difference, run the code below, line-by-line:
x <- c(1, 2, NA, 4, "cat1989dog", 5)
as.numeric(x)
readr::parse_number(x)
as.numeric() turns values that contain strings into NA; parse_number() extracts the first number it finds, dropping any non-numeric characters before the first number and all characters after the first number.
To see the difference, run the code below, line-by-line:
x <- c(1, 2, NA, 4, "cat1989dog", 5)
as.numeric(x)
readr::parse_number(x)
as.numeric() turns values that contain strings into NA; parse_number() extracts the first number it finds, dropping any non-numeric characters before the first number and all characters after the first number.
To see the difference, run the code below, line-by-line:
x <- c(1, 2, NA, 4, "cat1989dog", 5)
as.numeric(x)
readr::parse_number(x)
Have any questions? Put them below and we will help you out!
Course Content
132 Lessons
You need to be signed-in to comment on this post. Login.
Halima NAJIHI • April 23, 2026
I think both 2 and 3 are correct here isn't it?
Gracielle Higino Coach • April 23, 2026
Hi Halima! Thank you for pointing it out! Turns out the feature of checking two answers as correct was not working, so I've updated the quiz to have only one correct answer now. [=