user3099627
user3099627

Reputation: 65

How to remove n lines from txt-file in R?

I have txt-files with data arranged in columns, but with a fixed number of textlines (12 in this casee) with comments/general info. I need to remove these textlines (l. 1-12) in order to be able to read the files as a dataframe. Can this be done in R?

Upvotes: 1

Views: 5067

Answers (2)

James
James

Reputation: 66844

You can use the skip arugment to read.table:

read.table("file.txt", skip=12)

From the help:

skip integer: the number of lines of the data file to skip before beginning to read data.

Upvotes: 2

agstudy
agstudy

Reputation: 121578

Use skip argument of read.table:

read.table(text=' bla
           bla
           x y
           1 2',header=TRUE,skip=2)
  x y
1 1 2

Or using readLines and remove the first 12 rows.

Upvotes: 4

Related Questions