Re: [R] rounding down with as.integer

2015-01-02 Thread Duncan Murdoch
On 01/01/2015 10:05 PM, Mike Miller wrote: On Thu, 1 Jan 2015, Duncan Murdoch wrote: On 01/01/2015 1:21 PM, Mike Miller wrote: I understand that it's all about the problem of representing digital numbers in binary, but I still find some of the results a little surprising, like that list

Re: [R] rounding down with as.integer

2015-01-02 Thread peter dalgaard
On 02 Jan 2015, at 04:05 , Mike Miller mbmille...@gmail.com wrote: ...but why are we seeing errors so much bigger than the machine precision? Why does it change at 2? Because relative errors in the one-thousands part are roughly a thousand times bigger than errors in the number itself?

Re: [R] rounding down with as.integer

2015-01-02 Thread Mike Miller
On Fri, 2 Jan 2015, Duncan Murdoch wrote: On 01/01/2015 10:05 PM, Mike Miller wrote: This is how big those errors are: 512*.Machine$double.eps [1] 1.136868e-13 Under other conditions you also were seeing errors of twice that, or 1024*.Machine$double.eps. It might not be a coincidence

Re: [R] rounding down with as.integer

2015-01-01 Thread Duncan Murdoch
On 01/01/2015 2:43 PM, Mike Miller wrote: On Thu, 1 Jan 2015, Duncan Murdoch wrote: On 01/01/2015 1:21 PM, Mike Miller wrote: On Thu, 1 Jan 2015, Duncan Murdoch wrote: On 31/12/2014 8:44 PM, David Winsemius wrote: On Dec 31, 2014, at 3:24 PM, Mike Miller wrote: This is probably a FAQ,

Re: [R] rounding down with as.integer

2015-01-01 Thread Mike Miller
On Thu, 1 Jan 2015, Duncan Murdoch wrote: On 01/01/2015 1:21 PM, Mike Miller wrote: On Thu, 1 Jan 2015, Duncan Murdoch wrote: On 31/12/2014 8:44 PM, David Winsemius wrote: On Dec 31, 2014, at 3:24 PM, Mike Miller wrote: This is probably a FAQ, and I don't really have a question about it,

Re: [R] rounding down with as.integer

2015-01-01 Thread Richard M. Heiberger
Interesting. Following someone on this list today the goal is input the data correctly. My inclination would be to read the file as text, pad each number to the right, drop the decimal point, and then read it as an integer. 0 1 2 0.325 1.12 1.9 0.000 1.000 2.000 0.325 1.120 1.900 1000 2000

Re: [R] rounding down with as.integer

2015-01-01 Thread Mike Miller
On Thu, 1 Jan 2015, Duncan Murdoch wrote: On 31/12/2014 8:44 PM, David Winsemius wrote: On Dec 31, 2014, at 3:24 PM, Mike Miller wrote: This is probably a FAQ, and I don't really have a question about it, but I just ran across this in something I was working on: as.integer(1000*1.003)

Re: [R] rounding down with as.integer

2015-01-01 Thread Duncan Murdoch
On 31/12/2014 8:44 PM, David Winsemius wrote: On Dec 31, 2014, at 3:24 PM, Mike Miller wrote: This is probably a FAQ, and I don't really have a question about it, but I just ran across this in something I was working on: as.integer(1000*1.003) [1] 1002 I didn't expect it, but maybe I

Re: [R] rounding down with as.integer

2015-01-01 Thread Duncan Murdoch
On 01/01/2015 1:21 PM, Mike Miller wrote: On Thu, 1 Jan 2015, Duncan Murdoch wrote: On 31/12/2014 8:44 PM, David Winsemius wrote: On Dec 31, 2014, at 3:24 PM, Mike Miller wrote: This is probably a FAQ, and I don't really have a question about it, but I just ran across this in something I

Re: [R] rounding down with as.integer

2015-01-01 Thread Mike Miller
On Thu, 1 Jan 2015, Duncan Murdoch wrote: On 01/01/2015 1:21 PM, Mike Miller wrote: I understand that it's all about the problem of representing digital numbers in binary, but I still find some of the results a little surprising, like that list of numbers from the table() output. For

Re: [R] rounding down with as.integer

2015-01-01 Thread Mike Miller
I'd have to say thanks, but no thanks, to that one! ;-) The problem is that it will take a long time and it will give the same answer. The first time I did this kind of thing, a year or two ago, I manipulated the text data to produce integers before putting the data into R. The data were a

Re: [R] rounding down with as.integer

2015-01-01 Thread Ted Harding
I've been followeing this little tour round the murkier bistros in the back-streets of R with interest! Then it occurred to me: What is wrong with [using example data]: x0 - c(0,1,2,0.325,1.12,1.9,1.003) x1 - as.integer(as.character(1000*x0)) n1 - c(0,1000,2000,325,1120,1900,1003) x1 -

Re: [R] rounding down with as.integer

2015-01-01 Thread Mike Miller
Yes, Ted, that also works, but it's very slow: # read in values: data - scan( file=RECIP_IN, what=double(), nmax=recip_N*16000) Read 48013406 items # convert to integer by adding .5 and rounding down: ptm - proc.time() ; ints - as.integer( 1000 * data + .5 ) ; proc.time()-ptm user

[R] rounding down with as.integer

2014-12-31 Thread Mike Miller
This is probably a FAQ, and I don't really have a question about it, but I just ran across this in something I was working on: as.integer(1000*1.003) [1] 1002 I didn't expect it, but maybe I should have. I guess it's about the machine precision added to the fact that as.integer always

Re: [R] rounding down with as.integer

2014-12-31 Thread David Winsemius
On Dec 31, 2014, at 3:24 PM, Mike Miller wrote: This is probably a FAQ, and I don't really have a question about it, but I just ran across this in something I was working on: as.integer(1000*1.003) [1] 1002 I didn't expect it, but maybe I should have. I guess it's about the machine

Re: [R] rounding down with as.integer

2014-12-31 Thread Zaid Bhatti
How can I unsubscribe to not receive loop e mails? Sent from my Huawei Mobile David Winsemius dwinsem...@comcast.net wrote: On Dec 31, 2014, at 3:24 PM, Mike Miller wrote: This is probably a FAQ, and I don't really have a question about it, but I just ran across this in something I was

Re: [R] rounding down with as.integer

2014-12-31 Thread David Winsemius
Read the message at the bottom of every message from rhelp. -- David. On Dec 31, 2014, at 8:09 PM, Zaid Bhatti wrote: How can I unsubscribe to not receive loop e mails? Sent from my Huawei Mobile David Winsemius dwinsem...@comcast.net wrote: On Dec 31, 2014, at 3:24 PM, Mike Miller