Align numerical precision Excel 2013 and R

Tags: r excel
By : Max M

It is a rather broad question, but I replicated an Excel model in R. R produces almost the same results as excel, but there is always a slight % deviation in the range of 10^-8. I assume this is due to numerical precision. The model uses only basic arithmetic operations. My question would be: is there a simple way to force R to use the same numerical precision as Excel?

By : Max M


Probably not. R always uses double-precision (i.e., 8-byte) floating point, and and it seems that's also what Excel uses.

It is indeed mildly surprising that the results are not identical if you're only doing simple arithmetic, but note that even changing the sequence of arithmetic operations can change the results (i.e., floating-point arithmetic is not associative: (a+b)+c != a+(b+c), so if arithmetic is done left-to-right, a+b+c != c+b+a). It's probably impossible to even know what Excel is doing under the hood, although this (which may? only apply to Excel 2003) states points at which Excel deviates from the IEEE 754 standard used by R and most other numerical programs.

You might be able to get exact equality by working up from simple to more complex examples, seeing where the divergence occurs, and rearranging your computations to avoid the problem, but unless this equality is extremely important to you/worth investing a lot of effort, you may be better off testing for approximate equality.

It's conceivable that export to CSV is losing precision (e.g. see here).

Here it seems that your theme is cause this error:

You need to use a Theme.AppCompat theme (or descendant) with the design library..

Try using another theme, Theme.AppCompat.Light or whatever.

Edit: Try this

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>


add this in xml file or check what is your App theme in style files and in manifest file which theme you are using ?

This video can help you solving your question :)
By: admin