Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I read csv with large numbers (probably scientific notation) in R?

Tags:

r

csv

excel

I have some 13-digit numbers in an XLS file and I use Excel to generate the CSV file because I need to process it in R.

Then when R read the CSV file, it cannot recognize the big numbers. For example, 1329100082670 would appear like 1.329E+12 in R and lost its precision.

I've tried to format the big numbers as text in Excel and then save it as CSV but that didn't work!

Thanks in advance!

like image 417
Natalia Avatar asked Jun 23 '14 06:06

Natalia


People also ask

How do I get out of scientific notation in R?

You can disable scientific notation in the entire R session by using the scipen option. Global options of your R workspace. Use options(scipen = n) to display numbers in scientific format or fixed. Positive values bias towards fixed and negative towards scientific notation.

How do you avoid large numbers in scientific notation in R?

If you want to avoid scientific notation for a given number or a series of numbers, you can use the format() function by passing scientific = FALSE as an argument.

How do I stop e+ in R?

Method 1: Using scipen option In order to eliminate the exponential notation of the integer, we can use the global setting using options() method, by setting the scipen argument, that is options(scipen = n).


1 Answers

The numbers are probably all there, by default R doesn't aways show them. See

> a<-1329100082670
> a
[1] 1.3291e+12
> dput(a)
1329100082670

The dput() shows all the digits are retained even if they display on screen in scientific notation. You can discourage R from using scientific notation by setting the scipen option. Something like

options(scipen=999)

will turn off most scientific notation. But really, what it looks like on screen shouldn't be too important to you hopefully.

like image 135
MrFlick Avatar answered Oct 26 '22 17:10

MrFlick