Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7860223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:11:57+00:00 2026-06-02T22:11:57+00:00

I have a file that is tab-delimited and contains multiple tables each headed by

  • 0

I have a file that is tab-delimited and contains multiple tables each headed by a title, for example “Azuay\n”, “Bolivar\n”, “Cotopaxi\n”, etc, and each table separated by two newlines. Within R, how can I read in this file and select only the table (i.e. specified rows) corresponding to e.g. “Bolivar”, while ignoring the table beneath corresponding to “Cotopaxi” and the table above corresponding to “Azuay”.

NB. I’d prefer not to modify the table outside R.

The data looks like this. The file is tab-separated.

 Azuay
 region begin       stop
 1A     2017761     148749885
 1A     148863885   150111299
 1A     150329391   150346152
 1A     150432847   247191037


 Bolivar
 region begin           stop 
 2A     2785            242068364
 2A     736640          198339289


 Cotopaxi
 region begin           stop 
 4A     2282            9951846
 4A     11672561        11906166
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:11:59+00:00Added an answer on June 2, 2026 at 10:11 pm

    This seems to do the job:

    read.entry.table <- function(file, entry) {
    
       lines <- readLines(file)
    
       table.entry <- lines == entry
       if (sum(table.entry) != 1) stop(paste(entry, "not found"))
    
       empty.lines <- which(lines == "")
       empty.lines <- c(empty.lines, length(lines) + 1L)
    
       table.start <- which(table.entry) + 1L
       table.end   <- empty.lines[which(empty.lines > table.start)[1]] - 1L
    
       return(read.table(textConnection(lines[seq(from = table.start,
                                                  to   = table.end)]),
                         header = TRUE))
    }
    
    read.entry.table("test.txt", "Bolivar")
    #   region  begin      stop
    # 1     2A   2785 242068364
    # 2     2A 736640 198339289
    
    read.entry.table("test.txt", "Cotopaxi")
    #   region    begin     stop
    # 1     4A     2282  9951846
    # 2     4A 11672561 11906166
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tab delimited file that contains date, header row, some values, empty
I have a tab-delimited text file that I am parsing. Its first column contains
Let's say I have a tab-delimited text file that contains data arranged in columns
I have an ASCII file that contains tab-delimited data like this: Test_Version=2.5.3 Model-Manufacturer=D12-500 Test_Version=2.5.3
I have a tab-delimited file that has over 200 million lines. What's the fastest
I have a tab delimited file on a shared path. I've setup that flat
I have a text file that is tab-delimited. How can I separate this string
I have a text file that is tab delimited and looks like: 1_0 NP_045689
I read in a text file that is tab delimited, i then have a
So I have a tab delimited file that I need to insert through sqlbulkinsert.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.