read.xlsx2 returning NaN

107 views
Skip to first unread message

phillipsan...@gmail.com

unread,
Sep 14, 2015, 9:05:41 PM9/14/15
to R-package-xlsx
Hi

I have two questions:

1. what is the difference between read.xlsx and read.xlsx2

2. when I try to read my excel sheet in r using: 
dd<-read.xlsx2("Fx data (revised).xlsx",sheetIndex=5)
.. I get two different results. If I use read.xlsx i get something like:

           Date  Close AUD.deposit USD.deposit Impl.Vol NA. NA..1 NA..2 NA..3 NA..4 NA..5
1    1998-05-13 0.6309      4.8500      5.4844  13.0000  NA    NA    NA    NA    NA    NA
2    1998-05-20 0.6266      4.9000      5.5156  13.0000  NA    NA    NA    NA    NA    NA
3    1998-05-27 0.6207      4.8250      5.5469  11.7500  NA    NA    NA    NA    NA    NA
4    1998-06-03 0.6102      4.8000      5.5156  12.2500  NA    NA    NA    NA    NA    NA

... after 867 points (where my data in excel stops) every column is NA all the way down to point 4557


If I use read.xlsx i get something like:

          Date  Close AUD.deposit USD.deposit Impl.Vol 
1    1998-05-13 0.6309      4.8500      5.4844  13.0000 
2    1998-05-20 0.6266      4.9000      5.5156  13.0000 
3    1998-05-27 0.6207      4.8250      5.5469  11.7500 
4    1998-06-03 0.6102      4.8000      5.5156  12.2500 

... but again after 867 points NA's follow down to point 4557.

What am I doing wrong ?


Adrian Dragulescu

unread,
Sep 14, 2015, 9:11:44 PM9/14/15
to R-package-xlsx
The difference is internal.  You may think that columns 6 and over are empty, but they are created in the spreadsheet.  If you want to control which columns you bring in, you can specify that with read.xlsx2.  

Also the rows all the way to 4557 you "see" them empty, but they are created in the spreadsheet.  If you don't want to read them in, delete them from the spreadsheet, or read only the rows that you need. 

Or you can discard the rows with NA data directly in R. 

Adrian

--
You received this message because you are subscribed to the Google Groups "R-package-xlsx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-package-xls...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages