Natalia
Natalia

Reputation: 399

How do I read large numbers precisely in R and perform arithmetic on them?

I am reading a csv file with some really big numbers like 1327707999760, but R automatically converts it into 1.32771e+12. I've tried to assign it a double class but it didn't work because it's already a rounded value. I've checked other posts like Preserving large numbers . People said "It's not in a "1.67E+12 format", it just won't print entirely using the defaults. R is reading it in just fine and the whole number is there." But when I tried to do some arithmetic things on them, it's just not right. For example:

test[1,8]
[1] 1.32681e+12
test[2,8]
[1] 1.32681e+12
test[2,8]-test[1,8]
[1] 0

But I know they are different numbers!

Upvotes: 1

Views: 2190

Answers (2)

IRTFM
IRTFM

Reputation: 263342

Excel allows custom formats: Format/Cells/Custom and enter #0

Upvotes: 3

Matthew Lundberg
Matthew Lundberg

Reputation: 42649

That's not large. It is merely a representation problem. Try this:

options(digits=22)

options('digits') defaults to 7, which is why you are seeing what you do. All twelve digits are being read and stored, but not printed by default.

Upvotes: 6

Related Questions