Skip to content
Prev 2014 / 15274 Next

file import

On Jan 18, 2008 6:14 PM, ShyhWeir Tzang <swtzang at gmail.com> wrote:
Read it once with count.fields and then a second
time with read.table setting nrows.  The following
assumes that there is always a blank line following
the data.  You may need to generalize this if that's
not always so.  (If you can control the imput format
then an even easier thing to do is to ensure that
the comments are prefaced by the comment.char,
an argument to read.table)

Lines <- " header1  header2  header3
   100        200        300
    400       500        600
    700       800        900

comments
"
k <- count.fields(textConnection(Lines), blank.lines.skip = FALSE)
read.table(textConnection(Lines), header = TRUE, nrows = which(k==0)[1]-2)