Whats the difference between parse_number and as.numeric (R)?

Question:

Hello everyone, may i know what is the difference between parse_number and as.numeric in R? could you give me examples of how they are different?

Thank you!

Hello @lauratangwt, parse_number will drops any non-numeric characters before or after the first number.

> library(readr)
> parse_number('Victor is 17 years')
[1] 17

as.numeric will test an object and coerce to numeric

> as.numeric("90")
[1] 90
> as.numeric("90r")
[1] NA
Warning message:
NAs introduced by coercion
2 Likes

Thank you so much! You’ve been great at answering all my questions! Really appreciate it :slight_smile:

2 Likes