Skip to content
Coming soon: Ally. Your guide to the world of AI and R. Learn More →
R for the Rest of Us Logo

R in 3 Months (Fall 2026)

Quiz

Quiz

1.

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 &lt;- 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!

You need to be signed-in to comment on this post. Login.

Halima NAJIHI

Halima NAJIHI • April 23, 2026

I think both 2 and 3 are correct here isn't it?

Gracielle Higino

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. [=

Course Content

132 Lessons