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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:05:06+00:00 2026-05-29T23:05:06+00:00

I’m working with emergency room ICD-9 code data (health diagnoses), which are three-digit codes

  • 0

I’m working with emergency room ICD-9 code data (health diagnoses), which are three-digit codes with up to 2 decimals after (examples: 499, 499.1, 499.51, etc). Some special codes have the letter “V” instead of a first digit, such as “V10.46”.

Every emergency room visit (row) can have up to 11 diagnoses codes (columns), so I used reshape() to change the dataset to long format. Now I want to use floor() to remove those decimal points. But R can’t floor something with a character! I get this error: Error in Math.factor(dtl$diag) : floor not meaningful for factors

This post had some relevance but I’m wondering if there’s a better way? R: Remove character observations in a variable

Any ideas?

  • 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-29T23:05:09+00:00Added an answer on May 29, 2026 at 11:05 pm

    Building off @Vincent Zoonekynd’s excellent answer, If the aim was to use floor on the data, you can just strip the “V” and call floor on the rest:

    x <- c("499", "499.1", "499.51", "V10.46")
    # replace all occurences of "V" with nothing ("") in x:
    x.stripped <- gsub("V", "", x) 
    # convert to numeric so we can use floor():
    x.floor <- floor(as.numeric(x.stripped))
    

    Based off your error message, “not meaningful for factors”, that column of your data has been read in as strings (because of the “V” in some of the rows), and the default behaviour of R is to convert string columns into factors (like categories).

    If you get an error about gsub not working on factors, you need to convert your column to strings first:

    mydf$columname <- as.character(mydf$columnname)
    

    And then you can proceed as before.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I want to construct a data frame in an Rcpp function, but when I
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.