-2

I have data in excel and after reading in R it reads as follows as

lob2            lob3
1.86E+12    7.58E+12

I want it as

lob2                    lob3
1857529190776.75    7587529190776.75

This difference causes me to have different results after doing my analysis later on

Simon O'Hanlon
  • 58,647
  • 14
  • 142
  • 184
VASISTA
  • 33
  • 1
  • 6
  • 4
    `options(scipen=12)` and see [here for explanation](http://stackoverflow.com/a/16356730/1478381) – Simon O'Hanlon Apr 07 '15 at 14:57
  • 2
    are you sure this is not just the way the numbers are printing? how does `print(lob2, digits = 15)` look? are all of your numbers `xxx7529190776.75`? – rawr Apr 07 '15 at 14:58

1 Answers1

1

How is the data stored in Excel (does it think it is a number, a string, a date, etc.)?

How are you getting the data from Excel to R? If you save the data as a .csv file then read it into R, look at the intermediate file, Excel is known to abbreviate when saving and R would then see character strings instead of numbers. You need to find a way to tell excel to export the data in the correct format with the correct precision.

If you are using a package (there are more than 1) then look into the details of that package for how to grab the numbers correctly (you may need to make changes in Excel so that it knows they are numbers).

Lastly, what does the str function on your R object say? It could be that R is storing the proper numbers and only displaying the short version as mentioned in the comments. Or, it could be that R received strings that did not convert nicely to numbers and is storing them as characters or factors. The str function will let you see how your data is stored in R, and therefore how to convert or display it correctly.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110