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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:14:11+00:00 2026-06-11T21:14:11+00:00

This question perhaps has been answered earlier, but I did not see an answer.

  • 0

This question perhaps has been answered earlier, but I did not see an answer.

I have a data set that consists of numbers and missing values. One row is a percentage. Below is a small set of fake data where AA, BB and CC are the column names. The third row in this data set is the percentage.

   AA    BB    CC
  234   432    78
 1980  3452  2323
 91.1    90  93.3
   34   123    45

In this case, when I read the data set AA and CC are numeric and BB is integer. I guess somewhere 90.0 was rounded to 90. If I do not specify that BB is numeric could this cause problems with basic arithmetic?

I believe that if dd = 1 and ee = 2 and both are integer then the C language says dd / ee = 0, while R says dd / ee = 0.5.

Below is a series of simple mathematical operations that all seem to suggest answers in R are not changed regardless of whether the data are numeric or integer. Nevertheless, I keep thinking that it would be smart to specify that all variables are numeric when reading the data. Using Google I have found an example or two where the data type did seem to make a difference, but not below.

aa <- c(1,2,3,4,5,6,7)
bb <- 2
str(aa)
str(bb)

cc <- as.integer(aa)
dd <- as.integer(bb)
str(cc)
str(dd)

aa/bb
cc/dd
aa/dd
cc/bb

ee <- aa * aa
str(ee)
sum(ee/2)

ff <- cc * cc
str(ff)
sum(ff/2)

gg <- 4.14

hh <- ((aa * aa) * gg) / 2
hh
ii <- ((cc * cc) * gg) / 2
ii

jj <- (aa * aa) / gg
jj
kk <- (cc * cc) / gg
kk
jj == kk

mm <- as.integer(1)
nn <- as.integer(2)
mm/nn

I guess I am hoping for reassurance that this is not likely an issue with simple math, but I suspect it can. I keep thinking there is a fundamental rule of programming here, but I am not sure what that is. (I am aware of the concept of double precision.)

Thanks for any advice with what is surely a basic issue.

  • 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-11T21:14:12+00:00Added an answer on June 11, 2026 at 9:14 pm

    Division using the / operator will always return a “numeric”, i.e. the equivalent of a C “double”. The numerators and denominators are first coerced to numeric and then the division is done. If you want to use integer division you can use %/%. If you want to create an integer then you can use trunc or floor or you can use round(x , 0) or you can use as.integer. The first second and fourth of those options are equivalent. The round function will still return “numeric” even though the printed representation appears integer. I do not think you need to worry as long as you will be happy with “double”/”numeric” results. Heck, we even allow division by 0.

    Your ‘aa’ variable was classed as “numeric” despite being entered as a bunch of integers but had you used:

    aa <- 1:8  # sequences are integer class.
    

    It sounds as though you will not be too surprised by FAQ 7.31

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

Sidebar

Related Questions

Perhaps this question has been asked elsewhere, but I'm unable to find it. With
This question has been asked before perhaps multiple times, but I can't get the
I have tried contacting tech support with this question, but it has been over
Perhaps this question has been asked before in a different way, but I haven’t
Apologies if this question has been asked already, but suppose we have this code
I know this question has been asked before but I have a design question
I am guessing this question has been asked many times, but i could not
I have an ObjectDataSource (but perhaps this question is the same for all kinds
I know this sort of question has been asked before , but I still
I'm well aware that variants of this question have been asked before, but I

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.