[R] read.csv, header=TRUE but skip the first line

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun Jun 28 23:18:58 CEST 2009


Mark Knecht wrote:
> Hi,
>    Complete newbie to R here. Just getting started reading manuals and
> playing with data.
> 
>    I've managed to successfully get my *.csv files into R, however I
> have to use header=FALSE because the real header starts in line #2.
> The file format looks like:
> 
> PORTFOLIO EQUITY TABLE
> 
> TRADE,MARK-SYS,DATE/TIME,PL/SIZE,PS METHOD,POS SIZE,POS
> PL,DRAWDOWN,DRAWDOWN(%),EQUITY
> 
> 1,1,1/8/2004 12:57:00 PM,124.00,As Given,1,124.00,0.00,0,"10,124.00"
> 2,1,1/14/2004 9:03:00 AM,-86.00,As Given,1,-86.00,86.00,0.849,"10,038.00"
> 3,1,1/14/2004 11:51:00 AM,-226.00,As Given,1,-226.00,312.00,3.082,"9,812.00"
> 4,1,1/15/2004 12:57:00 PM,134.00,As Given,1,134.00,178.00,1.758,"9,946.00"
> 
> where the words "PORTFOLIO EQUITY TABLE" make up line 1, the rest of
> the text is on line 2, and then the lines starting with numbers are
> the real data. (Spaces added by me for email clarity only.)
> 
> If I remove the first line by hand then I can use header=TRUE and
> things work correctly, but it's not practical for me to remove the
> first line by hand on all these files every day.
> 
> I'd like to understand how I can do the read.csv but skip the first
> line. Possibly read the file, delete the first line and then send it
> to read.csv, or some other way?

Does it not work to set skip=1 in read.csv??

(With names like that, you might want check.names=FALSE too)

-- 
    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907




More information about the R-help mailing list