Skip to content
Prev 167602 / 398502 Next

read a xls file

On Tue, 2009-01-20 at 14:45 +0100, Ian Jenkinson wrote:
You did read ?read.table yes?

There are three arguments there that can help in such situations: 

'colClasses' allows the finest grained control over how R imports your
text files. You specify what each column is, noting that if you have
lots of columns, things like 

c("numeric", rep("character", 12))

will deal with runs of columns of the same type, without having to type
them all by hand.

'as.is' is a vector of logicals (TRUE/FALSE) that controls whether a
column is read in as is or converted.

'stringsAsFactors' a single logical. Should all character variables be
converted to factors.

Some of these would have been useful in your case.

I'm not sure what you tried, but I have found that saving an .xls file
as a CSV via OpenOffice.org (on Linux) and subsequently reading it in
with read.csv("foo.csv", ...) to be reasonably fool proof, especially
when one makes use of the arguments about for fine-grained processing.

Someone in this thread posted a response that included the use of RODBC,
which I haven't tried, but there are a plethora of ways to read data
from Excel without having to torture yourself and the data formats to do
so.

HTH

G