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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:57:24+00:00 2026-06-17T09:57:24+00:00

I have a dataframe that originated from an excel file. It has the usual

  • 0

I have a dataframe that originated from an excel file. It has the usual headers above the columns but some of the columns have % signs in them which I want to remove.

Searching stackoverflow gives some nice code for removing percentages from matrices, Any way to edit values in a matrix in R?, which did not work when I tried to apply it to my dataframe

as.numeric(gsub("%", "", my.dataframe))

instead it just returns a string of “NA”s with a warning message explaining that they were introduced by coercion. When I applied,

gsub("%", "", my.dataframe))

I got the values in “c(…)” form, where the … represent numbers followed by commas which was reproduced for every column that I had. No % was in evidence; if I could just put this back together … I’d be cooking.

Any help greatfully received, thanks.

  • 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-17T09:57:25+00:00Added an answer on June 17, 2026 at 9:57 am

    Based on @Arun’s comment and imaging how your data.frame looks like:

    > DF <- data.frame(X = paste0(1:5,'%'), 
                       Y = paste0(2*(1:5),'%'),
                       Z = 3*(1:5), stringsAsFactors=FALSE )
    
    > DF # this is how I imagine your data.frame looks like
       X   Y  Z
    1 1%  2%  3
    2 2%  4%  6
    3 3%  6%  9
    4 4%  8% 12
    5 5% 10% 15
    
    > # Using @Arun's suggestion
    > (DF2 <- data.frame(sapply(DF, function(x) as.numeric(gsub("%", "", x)))))
      X  Y  Z
    1 1  2  3
    2 2  4  6
    3 3  6  9
    4 4  8 12
    5 5 10 15
    

    I added as.numeric in sapply call for the resulting cols to be numeric, if I don’t use as.numeric the result will be factor. Check it out using sapply(DF2, class)

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

Sidebar

Related Questions

I have a data frame in R that has come about from running some
If I have a dataframe that has columns that include the same name, is
What I have: I have a master dataframe that has the following columns: userid,
I have a pandas DataFrame that has multiple columns in it: Index: 239897 entries,
I have a dataframe in R that I loaded from a CSV file. One
I have a data frame that is some 35,000 rows, by 7 columns. it
I have a dataframe that has two rows: | code | name | v1
I am reading a file into a Pandas DataFrame that may have invalid (i.e.
I have a dataframe of historical stock trades. The frame has columns like ['ticker',
I have a dataframe that has two sets of data that I need to

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.