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 8744511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:51:07+00:00 2026-06-13T11:51:07+00:00

I have this data: hhid perid actNo thisAct from to tripTime 8019450 1 1

  • 0

I have this data:

hhid    perid actNo thisAct from   to tripTime  
8019450     1     1    home  180 1051       NA  
8019450     1     2  school 1075 1245       24  
8019450     1     3  socrec 1255 1260       10  
8019450     1     4    home 1280 1619       20

Now, I want to insert three rows in which

thisAct=travel
from=(from-tripTime-1)
to=(from-1)

Then, the expected data look like this:

hhid    perid actNo thisAct from   to tripTime  
8019450     1     1    home  180 1051       NA  
*8019450    1     2  travel 1052 1074         
8019450     1     3  school 1075 1245       24  
*8019450    1     4  travel 1246 1254         
8019450     1     5  socrec 1255 1260       10  
*8019450    1     6  travel 1261 1279         
8019450     1     7    home 1280 1619       20  

Could you please how to insert those rows with asterisks?

Thank you.

  • 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-13T11:51:07+00:00Added an answer on June 13, 2026 at 11:51 am

    Start by recreating your data:

    dat <- read.table(text="
                      hhid    perid actNo thisAct from   to tripTime  
    c     1     1    home  180 1051       NA  
    8019450     1     2  school 1075 1245       24  
    8019450     1     3  socrec 1255 1260       10  
    8019450     1     4    home 1280 1619       20
                      ", header=TRUE)
    

    Now calculate the travel times and put it in a data frame with the same shape as your data

    travel <- data.frame(
      hhid = 8019450,
      perid = 1,
      actNo = NA,
      thisAct = "travel",
      from = head(dat$to + 1, -1),
      to   = tail(dat$from - 1, -1),
      tripTime = NA
    )
    

    then rbind and sort:

    x <- rbind(dat, travel)
    x <- x[order(x$from), ]
    x$perid <- seq_along(x$perid)
    x
    
         hhid perid actNo thisAct from   to tripTime
    1       c     1     1    home  180 1051       NA
    5 8019450     2    NA  travel 1052 1074       NA
    2 8019450     3     2  school 1075 1245       24
    6 8019450     4    NA  travel 1246 1254       NA
    3 8019450     5     3  socrec 1255 1260       10
    7 8019450     6    NA  travel 1261 1279       NA
    4 8019450     7     4    home 1280 1619       20
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this data from a xml file: <?xml version=1.0 encoding=utf-8 ?> <words> <id>...</id>
I have this html structure: <div id=home> <div class=section_header> <h1 class=left data-target=newest><?=lang('home_newest');?></h1> ... </div>
I have this data coming from a XML: var searched = from c in
I have this data spited out from my cake php query.. This is the
I have this data coming from a REST method using jquery's getJSON method. [Date.UTC(2010,0,0,0,0,0,0),
I have this data set from a textarea P234324, 2011-03-23 12:34:37 \nP234434, 2011-03-23 13:34:36
I have this data frame. I would like to create another data frame from
I have this data in cell A1: Majestic Properties Design District, LLC, Ste. 101,
i have this data | car_name | year | price | Honda | 2011
I have this data: /blabla/blabla (abs,def) /yxz I use this regex (.*)(?:\(([^$]*)\))?\n But it

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.