s-news
[Top] [All Lists]

Re: importing data into Splus - numbers changing

To: "Nicola Koper" <nkoper@yahoo.com>, "S-news" <s-news@wubios.wustl.edu>
Subject: Re: importing data into Splus - numbers changing
From: "Michael Camilleri" <MichaelCamilleri@branz.co.nz>
Date: Wed, 27 Feb 2008 09:09:40 +1300
In-reply-to: <133133.31044.qm@web36205.mail.mud.yahoo.com>
References: <133133.31044.qm@web36205.mail.mud.yahoo.com>
Thread-index: Ach4s4U1qUj2JaNAQVSU+rWE0OOO3w==
Thread-topic: importing data into Splus - numbers changing
It is possible that Excel has stored the number with all the trailing
nines. If you expand the number of decimal places you can find out.

SPlus interprets any formatting that Excel has when it decides how to
import the data. You could try removing all formatting from Excel. 

If you use the import data menu there is an option for rounding. You can
round to anything from 1-5 decimal places. You can call this function
from a script as guiImportData()

What type of data object are you importing to? If it has single
precision floating point it might cause the type of problem you are
having (although you usually have to specifically define this - the
default is double precision).

Computers generally store numbers as double precision floating point,
and as soon as you start to do anything but the most basic of
mathematical operations small errors creep in. To illustrate this, run
these in SPlus

101.3-101.3

101.3-101-0.3

The first gives the correct answer of 0, as the double precision
representation of 101.3 is always the same, so subtracting it from
itself gives exactly zero.

The second gives the answer -2.831069e-015, which shows the effect of
double precision calculations.

Interestingly this expression

101.3-0.3-101.0

Gives 0 as the result. Order of operation can be important.

This level of error is not usually a problem, unless you are concerned
with very small difference between large numbers, are combining very
small and very large numbers, or need dates accurate to fractions of a
second. 

Michael

<Prev in Thread] Current Thread [Next in Thread>