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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:20:40+00:00 2026-05-28T13:20:40+00:00

(I have modified this question to make it more explicit.) I have a dataset

  • 0

(I have modified this question to make it more explicit.)

I have a dataset as follows:

data <- structure(list(id = 1:12, personID = c(1L, 2L, 3L, 4L, 4L, 3L,
2L, 1L, 1L, 2L, 3L, 4L), lastName = structure(c(1L, 2L, 3L, 4L,
4L, 3L, 2L, 1L, 1L, 2L, 3L, 4L), .Label = c("james", "joan",
"lucy", "mary"), class = "factor"), date = structure(c(5L, 5L,
8L, 9L, 6L, 1L, 3L, 11L, 4L, 2L, 7L, 10L), .Label = c("1/01/2012",
"10/04/2011", "11/01/2012", "11/08/2011", "12/01/2012", "12/04/2012",
"12/12/2011", "14/01/2012", "16/01/2012", "24/06/2010", "24/06/2011"
), class = "factor"), status = c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 2L, 1L)), .Names = c("id", "personID", "lastName",
"date", "status"), class = "data.frame", row.names = c(NA, -12L
))

I need to extract a subset from the data frame to include records where each row occured more than once in a period of greater than 8 weeks.

The extraction needs to search from the oldest record and then select the next (more recent) additional record for the same personID that was greater then 8 weeks since the previous record. Upon finding another record older then 8 weeks it should repeat the process using what the more recent second record as the new starting point.

Thanks.

  • 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-28T13:20:41+00:00Added an answer on May 28, 2026 at 1:20 pm

    How about:

    maxDiff <- tapply(data$date,data$personID,function(x) max(dist(x)))
    subset(data,personID %in% names(maxDiff[maxDiff>(8*7)]))
      id personID lastName       date status
    1  1        1    james 2012-01-12      1
    4  4        4     mary 2012-01-16      1
    5  5        4     mary 2012-04-12      1
    8  8        1    james 2011-06-24      1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this timer function, it gives me following exception. Collection was modified; enumeration
I have a dataset that I have modified into an xml document and then
My apologies if this is too subjective of a question. I have a theory
EDIT: Optimization results at end of this question! hi, i have a following code
This question isn't about the technical usage of restricted, more about the subjective usage.
If so, how? Does this question even make sense? In my case it would
This is a process question, so there may be more than one right answer.
I have modified the Nerd Dinner application to allow editing of child records by
I have modified my MOSS 2007 configuration to query a given target AD successfully.
I have modified a working Windows service that had always been starting beforehand. After

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.