Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8819657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:24:58+00:00 2026-06-14T05:24:58+00:00

I have a file with internationally formatted numbers (i.e strings) including units of measurement.

  • 0

I have a file with internationally formatted numbers (i.e strings) including units of measurement. In this case the decimal place is indicated by “,” and the 1e3 seperator is indicated as “.” (i.e. German number formats).

a <- c('2.200.222   €',
       '  180.109,3 €')

or

b <- c('28,42 m²',
       '47,70 m²')

I’d like to convert these strings efficiently to numeric. I’ve tried to filter out numbers by codes like

require(stringr)
str_extract(a, pattern='[0-9]+.[0-9]+.[0-9]+')
str_extract(b, pattern='[0-9]+,[0-9]+')

however, this does seem to be too prone to errors and I guess there must be a more standardized way. So here’s my question: Is there a custom function, package or something else that is capable of such a problem?

Thank you very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:24:59+00:00Added an answer on June 14, 2026 at 5:24 am

    Here is a function that uses gsub to deal with the sample data you posted:

    x <- c('2.200.222   €', '  180.109,3 €', '28,42 m²', '47,70 m²')
    
    strip <- function(x){
      z <- gsub("[^0-9,.]", "", x)
      z <- gsub("\\.", "", z)
      gsub(",", ".", z)
    }
    
    as.numeric(strip(x))
    [1] 2200222.00  180109.30      28.42      47.70
    

    It works like this:

    1. First strip out all trailing non-digits (and anything after these non-digits)
    2. Then strip out all periods.
    3. Finally, convert commas to periods.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose that we have file like this: sometext11 sometext12 sometext13 sometext21 sometext22 sometext23 Texts
Suppose I have file which goes like this : a void measure() { a
In the web page, I have file upload widget. I need to show this
I have file with binary data. This is specification: The SRTM data files have
I have a file that has many xml-like elements such as this one: <document
I have the following file full of lines similar to this: line = 'Weclome
I have file with lines like so: 1 17 A G R:560:500:60:10.71%:1.6329E-19 Pass:1.0:276:0:57:0:1E0 15
I have file in json format of world-countries I want to change it to
I have file with name contact.php, inside I have form: <form method=post name=kontakt action=send_mail.php>
I have file locale/es/LC_MESSAGES/django.mo (and .po), ran makemessages and compilemessages. Definitely all messages are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.