0

Possible Duplicate:
Read an Excel file directly from a R script

I made an Excel file, I named it test.xlsx. I wanted to read the file in R.

date    price  
1        34  
2        34.5  
3        34  
4        34  
5        35  
6        34.5  
7        36  

Now, when I used

x = read.csv("test.xlsx")  

didn't work. Also I used

x = read.table("test.xlsx")

I got the warning

Warning message:
In read.table("test.xlsx") :
  incomplete final line found by readTableHeader on 'test.xlsx'  

and the result:

 V1
1                         PK\003\004\024
2 PˆTز\005›DQ4ï½ùfىé|[™d\003\001µ³9\033g

So, do I need to make a special file in order to read it in R?

Community
  • 1
  • 1
mzn.rft
  • 839
  • 3
  • 13
  • 20
  • http://stackoverflow.com/questions/6099243/read-an-excel-file-directly-from-a-r-script – Ben Bolker Oct 22 '12 at 20:50
  • Take note of the formatting (including basic punctuation and spelling) that I added to your question. Do please try to pay attention to these things if you ask more questions in the future. – joran Oct 22 '12 at 21:06

2 Answers2

2

try using a simple CSV file. you can save one in Excel using the Save As option

Frank Thomas
  • 2,434
  • 1
  • 17
  • 28
  • i was looking for this option , but i don't find it , i have other options , like excel workbook , excel binary workbook , or xml data , but i don't find csv option , is there other solution ? – mzn.rft Oct 22 '12 at 21:18
  • It's hard to believe you don't have a "Comma separated values (.csv)" option ... what version of Excel, under what OS? Please see all the answers to the linked question http://stackoverflow.com/questions/6099243/read-an-excel-file-directly-from-a-r-script (which you would have found by searching StackOverflow for "[r] read excel" ...) – Ben Bolker Oct 22 '12 at 21:21
  • i have Excel 2007 , and OS : WINDOWS XP pac3 – mzn.rft Oct 22 '12 at 21:30
  • 1
    Check out this page for instructions on how to save an excel spreadsheet to a .csv file:http://www.brighthub.com/computing/windows-platform/articles/30292.aspx . also note, its very east to create a csv file in notepad. each record is on its own line, and each value in a record is separated by a comma (eg: Comma Seperated Value). then just save and set your extension to .csv – Frank Thomas Oct 23 '12 at 02:18
0

You may want to have a look at the XLConnect package for dealing with Excel files in R: http://cran.r-project.org/web/packages/XLConnect/index.html

Martin Studer
  • 2,213
  • 1
  • 18
  • 23
  • see linked question http://stackoverflow.com/questions/6099243/read-an-excel-file-directly-from-a-r-script -- two of the answers reference XLConnect (this is why I've voted to close the question as an exact duplicate ...) – Ben Bolker Oct 22 '12 at 21:07
  • supposedly , this is the easiest kind of files to be read in r , but i am just lost , what is wrong with the file ? – mzn.rft Oct 22 '12 at 21:11