'Remove certain lines (with ---- and empty lines) from txt file using readLines() or read_lines()
I have this text file called textdata.txt:
TREATMENT DATA
------------------------------------
A: Text1
B: Text2
C: Text3
D: Text4
E: Text5
F: Text6
G: Text7
I would like to remove the whole line with --------- and the empty lines using readLines or read_lines:
When I use readLines("textdata.txt") I get:
[1] "TREATMENT DATA"
[2] ""
[3] "------------------------------------"
[4] "A: Text1"
[5] "B: Text2"
[6] ""
[7] "C: Text3"
[8] "D: Text4"
[9] ""
[10] "E: Text5"
[11] "F: Text6"
[12] "G: Text7"
I would like to have, expected output:
[1] "TREATMENT DATA"
[2] "A: Text1"
[3] "B: Text2"
[4] "C: Text3"
[5] "D: Text4"
[6] "E: Text5"
[7] "F: Text6"
[8] "G: Text7"
Background: I have de facto no experience handling files with R. The basic idea is to get a .txt format from which I can load multiple text files stored in a folder to one dataframe.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
