Haseeb Ahmed Khan
Haseeb Ahmed Khan

Reputation: 135

How to not read the commented lines in from a dataset in R?

I am reading a dataset where there are commented lines. I want to read the data from the dataset except the commented lines.

Dataset

I tried using this but it only removes the comments on top not all the commented lines in between the dataset.

Code

txt = readLines("offline.txt")
txt = txt[4:length(txt)

Dataset link

Upvotes: 0

Views: 75

Answers (1)

ThomasIsCoding
ThomasIsCoding

Reputation: 101678

I think you can try the code below, using grep + readLines

txt<-grep("^#",
           readLines("offline.txt"),
           invert = TRUE,
           value = TRUE)

where the idea behind is that you read all lines first and then filter out the commented lines (starting with #)

Upvotes: 1

Related Questions