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

  • SEARCH
  • Home
  • 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 6908257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:32:24+00:00 2026-05-27T08:32:24+00:00

I got a very long telephone log as a text file and I have

  • 0

I got a very long telephone log as a text file and I have tried to read it into R but it is not really working out. The text has a structure but it is most certainly not a table. Its structure is as follows

  1. Each record is composed of multiple lines so readLines is not quite appropriate
  2. Each line of each record is a separate field
  3. Some records have an additional field after the second field
  4. Each new record is noted by a blank line. readLines or scan would have worked if one could have specified that records were separated by “\n\n” and that fields (or columns) were separated by “\n”

Here is an example:

TheInstitute 5467
  telephone line 4125526987 x 4567
  datetime 2011110516 12:56
  blay blay blah who knows what, but anyway it may have a comma

TheInstitute 5467
  telephone line 4125526987 x 4567
  datetime 2011110516 12:58
  blay blay blah who knows what

TheInstitute 5467
  telephone line 412552999 x 4999
  bump phone line 4125527777
  datetime 2011110516 12:59
  blay blay blah who knows what

TheInstitute 5467
  telephone line 4125526987 x 4567
  bump phone line 4125527777
  datetime 2011110516 13:51
  blay blay blah who knows what, but anyway it may have a comma

TheInstitute 5467
  telephone line 4125526987 x 4567
  datetime 2011110516 14:56
  blay blay blah who knows what

How can I do this in R? I have tried tricks with scan, paste, strsplit but I am spinning in circles. I may have to get it into a list since that can handle non-equal number of elements. I would like to get all the records to have the same number of fields and for those records that do not have the one field (here called bump phone) I would like them just to have a NA as the value in that field. I would appreciate help even just to get started. From there I can play and toy.

  • 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-05-27T08:32:25+00:00Added an answer on May 27, 2026 at 8:32 am

    With multi.line = TRUE in the scan function, a record should end with two end-of-lines. I did this with textConnection around your file, but you would use a valid file name:

    inp <- scan(textConnection(txt), multi.line=TRUE, 
                 what=list(place="character", tline1="character", 
                 cline1="character", cline2 ="character", cline3="character"), sep="\n")
    Read 5 records
    > str(as.data.frame(inp))
    'data.frame':   5 obs. of  5 variables:
     $ place : Factor w/ 1 level "TheInstitute 5467": 1 1 1 1 1
     $ tline1: Factor w/ 2 levels "  telephone line 4125526987 x 4567",..: 1 1 2 1 1
     $ cline1: Factor w/ 4 levels "  bump phone line 4125527777",..: 2 3 1 1 4
     $ cline2: Factor w/ 4 levels "  blay blay blah who knows what",..: 2 1 3 4 1
     $ cline3: Factor w/ 3 levels "","  blay blay blah who knows what",..: 1 1 2 3 1
    > as.data.frame(inp)
                  place                             tline1
    1 TheInstitute 5467   telephone line 4125526987 x 4567
    2 TheInstitute 5467   telephone line 4125526987 x 4567
    3 TheInstitute 5467    telephone line 412552999 x 4999
    4 TheInstitute 5467   telephone line 4125526987 x 4567
    5 TheInstitute 5467   telephone line 4125526987 x 4567
                            cline1
    1    datetime 2011110516 12:56
    2    datetime 2011110516 12:58
    3   bump phone line 4125527777
    4   bump phone line 4125527777
    5    datetime 2011110516 14:56
                                                               cline2
    1   blay blay blah who knows what, but anyway it may have a comma
    2                                   blay blay blah who knows what
    3                                       datetime 2011110516 12:59
    4                                       datetime 2011110516 13:51
    5                                   blay blay blah who knows what
                                                               cline3
    1                                                                
    2                                                                
    3                                   blay blay blah who knows what
    4   blay blay blah who knows what, but anyway it may have a comma
    5                                                                
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a very long text file as a result of a test last
Well friends, I have got this query which works but is very long for
Have not worked with ASP in a very long time and have never dealt
I have got TD with long text in it. I'd like it to be
I've got a very long text (an HTML page actually) (almost an entire book)
I have Notepad++ and I got some XML code which is very long. When
We've got a query that is taking a very long time to complete with
I have got very big problem because I would like to get more information
How could this be happening? sqlite> select read, text from message; 1|No just got
I've got a query that is taking a very long time to run due

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.