Here is one way of doing this.
(1) read the whole file in as a vector of strings one line at a time
      x <- readLines("<path to your data file>")
(2) find the position of the "@DATA" string in your vector
      s <- which(x == "@DATA")
(3) scan the file again skipping s lines
      scan("<path to your data file>", skip=s, sep=",", ...)

You may want to consider using read.table instead of scan - it has the skip
parameter too.  Finally you could actually reuse x from (1) above by
something like
      x <- x[-(1:s])
      loop through elements of x and use the strsplit command to extract
numbers from each line
I suspect that this would be more cumbersome and slower than re-reading the
file skiiping s lines from the top.

Cheers,

Andy

__________________________________
Andy Jaworski
Engineering Systems Technology Center
3M Center, 518-1-01
St. Paul, MN 55144-1000
-----
E-mail: [EMAIL PROTECTED]
Tel:  (651) 733-6092
Fax:  (651) 736-3122


|---------+------------------------------>
|         |           Ko-Kang Kevin Wang |
|         |           <[EMAIL PROTECTED]|
|         |           and.ac.nz>         |
|         |           Sent by:           |
|         |           [EMAIL PROTECTED]|
|         |           ath.ethz.ch        |
|         |                              |
|         |                              |
|         |           12/20/2002 04:08   |
|         |                              |
|---------+------------------------------>
  
>-----------------------------------------------------------------------------------------------------------------------------|
  |                                                                                    
                                         |
  |      To:       R Help <[EMAIL PROTECTED]>                                   
                                         |
  |      cc:                                                                           
                                         |
  |      Subject:  [R] More on scan()                                                  
                                         |
  
>-----------------------------------------------------------------------------------------------------------------------------|



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

------------------------------------------------------------------------------

/* Time is the greatest teacher, unfortunately it kills its students */

Ko-Kang Kevin Wang
Master of Science (MSc) Student
Department of Statistics
University of Auckland
New Zealand
Homepage: http://www.stat.auckland.ac.nz/~kwan022

______________________________________________
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help

______________________________________________
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to