[R] More on scan()

Emmanuel Paradis paradis at isem.univ-montp2.fr
Fri Dec 20 00:10:03 CET 2002


At 10:08 20/12/2002 +1300, vous avez écrit:
>Hi,
>
>If I have a CSV file which has several comments at the top, and the data
>start immediately after the line:
>   @DATA
>
>Is it possible to use the scan() command to get the CSV data into R, by
>only reading the lines after @DATA?  If so, how can I do it?
>
>Cheers,
>
>Kevin


Here is a possible solution (if your data file is `yourfile.txt'):


tmp <- scan("yourfile.txt", what = "", sep = "\n")
skp <- grep("@DATA", tmp)
your.data <- scan("yourfile.txt", what = [...], skip = skp)


You may improve this by scanning line by line with:

scan("foo.txt", what = "", sep = "\n", n = 1, skip = s)

with s = 0, 1, 2, ... till you meet "@DATA".


Hope this helps.

EP

Emmanuel Paradis
Laboratoire de Paléontologie
Institut des Sciences de l'Évolution
Université Montpellier II
F-34095 Montpellier cédex 05
France
    phone: +33  4 67 14 39 64
      fax: +33  4 67 14 36 10
   mailto:paradis at isem.univ-montp2.fr
http://www.isem.univ-montp2.fr/ISEMFre/Equipes/PPP/PPerso/ParadisE.php




More information about the R-help mailing list