[R] reading Excel file

stephen sefick ssefick at gmail.com
Tue Mar 25 20:39:37 CET 2008


why can't you know the number of columns if it is an excel file?

On Tue, Mar 25, 2008 at 2:36 PM, Earl F. Glynn
<efg at stowers-institute.org> wrote:
> "Utkarsh Singhal" <utkarshs at ambaresearch.com> wrote in message
>  news:A36876D3F8A5734FA84A4338135E7CC3033BF22A at BAN-MAILSRV03.Amba.com...
>
> > Hi R,
>
>  > I have an excel file in which the third column is "date" and others are
>  > "character" and "numeric".
>  >
>
> > If I use this to read the file in R:   x = read.xls("D:\\file.xls")
>  >
>  > The problem is that my date column is read in julian dates.
>
>  RDOBC has its problems when all data in a column are not exactly the same
>  data type, but can read dates:
>
>  Consider an Excel file with the following: (view with fixed-width font):
>
>  Index   Label1  Date        Number   Label2  Mixed1  Mixed2
>  1       A       3/1/2008     12.45   X       1       A
>  2       B       3/2/2008     14.76   Y       2       B
>  3       C       3/3/2008     10.99   Z       A       1
>  4       D       3/4/2008     3.14            B       2
>
>  Use this to read the excel worksheet "Sheet1":
>
>  library(RODBC)
>  connection <- odbcConnectExcel("C:/temp/Sample.xls")
>  d <- sqlFetch(connection, "Sheet1")
>  odbcClose(connection)
>
>  d
>  class(d$Date)
>
>  > d
>   Index Label1       Date Number Label2 Mixed1 Mixed2
>  1     1      A 2008-03-01  12.45      X      1     NA
>  2     2      B 2008-03-02  14.76      Y      2     NA
>  3     3      C 2008-03-03  10.99      Z     NA      1
>  4     4      D 2008-03-04   3.14   <NA>     NA      2
>  > class(d$Date)
>  [1] "POSIXt"  "POSIXct"
>
>
>  efg
>  Earl F. Glynn
>  Bioinformatics
>  Stowers Institute for Medical Research
>
>
>
>  ______________________________________________
>  R-help at r-project.org mailing list
>  https://stat.ethz.ch/mailman/listinfo/r-help
>  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>  and provide commented, minimal, self-contained, reproducible code.
>



-- 
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

	-K. Mullis



More information about the R-help mailing list