Skip to content
Prev 222684 / 398500 Next

Ignoring initial rows in a text file import

try this:

input  <- readLines("yourfile.txt")
# determine start
start <- grep("\tBegin Main\t", input)[1]  # first line if many
if (length(start) == 1 && (start > 1)){
    input <- tail(input, -(start - 1))  # delete heading lines
}
# find lines you want to delete
breaks <- grep("\tBreak\t", input)
if (length(breaks) > 0){
    input <- input[-breaks]
}
# now read in your data
real_input <- read.table(textConnection(input), header=TRUE)
closeAllConnections()
On Mon, May 31, 2010 at 7:51 PM, Kevin Burnham <kburnham at gmail.com> wrote: