R - Reading lines from a .txt-file after a specific line

后端 未结 3 1053
心在旅途
心在旅途 2020-12-10 16:55

I have a bunch of output .txt-files that consists of a large parameter list and a X-Y-coordinate set. I need to extract these coordinates from all files so that only those l

3条回答
  •  清歌不尽
    2020-12-10 17:28

    This looks like a job for data.table's fread

    library(data.table)
    impcoord <- fread("file.txt",skip="coordinatesXY")
    

    --edit--

    That is why it is good to give a reproducible example. That error means your file is causing trouble.

    The skip command matches the text you give it to the file to identify what line to start at, so you need to give it a unique string from the start of the line that you want it to start reading from. That function would work for something like this:

    ## some random text
    ## some more random text
    ## More random text
    table_heading1, table_heading2, table_heading3 ...etc
    value1, value2, value3 ... etc
    etc
    
    Just_The_Table <- fread("the_above_as_a_text_file.txt", skip="table_heading1", header=T)
    

提交回复
热议问题