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 1008005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:42:13+00:00 2026-05-16T08:42:13+00:00

Possible Duplicate: How can I declare a thousand separator in read.csv? I actually have

  • 0

Possible Duplicate:
How can I declare a thousand separator in read.csv?

I actually have a solution for this problem, but I am curious if there is a better way to do what I was trying to do.

I scraped some data from the majorleaguesoccer.com and read it into R using

mls.reg.tmp <- read.table("../data/mls_reg_season_20100812.csv",
                          header = F, sep = ";")

Note that I used sep = “;” because some of the attendance figures where in the thousands on the websites and I scraped “as is”, e.g.,

> str(mls.reg.dat$a_tot)
 Factor w/ 164 levels " 166,060"," 171,282",..: 132 45 159 153 46 160 
158 148 150 98 ...

In hindsight, I should’ve just removed the commas in python in the pre-processing step of this project. I should also point out that there were some text fields in the data set as well.

> str(mls.reg.dat$team)
 Factor w/ 20 levels "Chicago Fire",..: 4 9 19 11 3 10 13 16 5 6 ...

Given that I want to use the attendance data as a numeric value, I converted using as.numeric and gsub. As an example in a call to ggplot:

ggplot(data = mls.reg.dat, aes(x = as.numeric(gsub(",", "", 
  mls.reg.dat$a_tot)), y = sog)) + geom_point() + 
  facet_wrap(~ team)

Question: Is this the most efficient way of working with data such as this? Or is there a specialized function for doing something along these lines?

I’m posting the question here because I spent quite a bit of time (> 30 min) just working in this simple solution and thought that others might benefit from this as well.

  • 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-05-16T08:42:13+00:00Added an answer on May 16, 2026 at 8:42 am

    I am not aware of any specialised function, but you could do it directly when you read the data.

      data <- read.table(...)
      data$someColumn <- as.numeric(gsub(",", "", data$someColumn))
    

    Any subsequent call can be made using data$someColumn, without need of further conversion (and easier-to-read code)

    EDIT: seems to be duplicate of “How can I declare a thousand separator in read.csv?”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can someone Explain this jQuery code? I have posted this before, but
Possible Duplicate: Can select * usage ever be justified? Curious to hear this from
Possible Duplicate: declare property as object? in java you can create an object directly
Possible Duplicate: How can I rearrange string with SQL? Declare @CustTotalCount as int Declare
Possible Duplicate: What describes @property(…) best? What's that actually good for? If I declare
Possible Duplicate: Can't pass mysqli connection in session in php Many of us have
Possible Duplicate: Covariance and Contravariance on the same type argument You can declare a
Possible Duplicate: Can I set a breakpoint on 'memory access' in GDB? I have
Possible Duplicate: Can’t operator == be applied to generic types in C#? I've got
Possible Duplicate: Can’t operator == be applied to generic types in C#? I've coded

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.