Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

how to parse a text file that contains the column names at the beginning of the file?

$
0
0

My text file looks like the following

"
file1
cols=
col1
col2
# this is a comment
col3

data
a,b,c
d,e,f
"

As you can see, the data only starts after the data tag and the rows before that essentially tell me what the column names are. There could be some comments which means the number of rows before the data tag is variable.

How can I parse that in R? Possibly with some tidy tools? Expected output is:

# A tibble: 2 x 3
  col1  col2  col3 
  <chr> <chr> <chr>
1 a     b     c    
2 d     e     f  

Thanks!


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>