Skip to content
R for the Rest of Us Logo

R in 3 Months (Spring 2026)

Quiz

Quiz

1.

What is the difference between as.numeric() and parse_number()?

parse_number() extracts the last number it finds, dropping any non-numeric characters before the last number.

as.numeric() turns values that contain strings into NA;parse_number() extracts the last number it finds, dropping any non-numeric characters before the last 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 last number it finds, dropping any non-numeric characters before the last 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)

parse_number() extracts the last number it finds, dropping any non-numeric characters before the last number.

Have any questions? Put them below and we will help you out!

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

Course Content

144 Lessons