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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:46:18+00:00 2026-06-16T16:46:18+00:00

I have this data.frame : df <- read.table(text= section to from time a 1

  • 0

I have this data.frame :

df <- read.table(text= "   section to from    time
                             a     1  5        9       
                             a     2  5        9        
                             a     1  5        10       
                             a     2  6        10       
                             a     2  7        11       
                             a     2  7        12       
                             a     3  7        12       
                             a     4  7        12
                             a     4  6        13  ", header = TRUE)   

Each row identifies the simultaneoues occurence of an id in to and from at a timepoint time. Basically a time explicit network of ids in to and from.

I want to know which to ids shared a from id within a particular time range which is 2. In otherwards i want to know if ids 1 and 2 in to both went to coffee shop 5 within two days of each other., i.e.

id 1 and 2 in to shared id 5 in from at time 9 and 10 respectively and so would have 1 shared events within the time window 2. If they also shared a from id at time point 13 e.g.

                             a     1  5        9       
                             a     2  5        9        
                             a     1  7        13       
                             a     2  7        13       

then 1 and 2 would get a 2

So the final output I would like for the df would be:

                           section to.a to.b    noShared
                             a     1    2        1       
                             a     2    3        1        
                             a     2    4        1       
                             a     3    4        1       

I can get some of the way there with:

library(plyr)                            
library(tnet)


a <- ddply(df, .(section,to,time), function(x)  
          data.frame(from = unique(x$from)) )

b <- ddply(a, .(section,time), function(x) {

            b <- as.tnet(x[, c("to","from")], type="binary two-mode tnet")
            b <- projecting_tm(b, method="sum")
            return(b)

       })

This gets me which ids in to shared ids in from within each time point.

However there are two main problems with b.

Firstly within each time point the pairs of ids appear twice in both directions i.e.

 1  2  5  9 # id 1 and 2 went to coffee shop 5  at time 9
 2  1  5  9 # id 2  and 1 went to coffee shop 5 at time 9

 I only want each sombination to appear once: 

  1  2  5  # id 1 and 2 went to coffee shop 5  at time 9</strike> 

Secondly I need to bin the results within the time window so that my final result doesnt hav time just number of shared events i.e.


EDIT

The time issue has more issues than expected. The first problem is enough for this question.

  • 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-16T16:46:19+00:00Added an answer on June 16, 2026 at 4:46 pm

    for the generation of b (first part of the question)

    I change the code projecteing_tm wihch is transformation of a network.

    b <- ddply(a, .(section,time), function(x) {
      ## first I create the origin network
      net2 <- x[, c("to","from")]
      colnames(net2) <- c('i','p')
      net2 <- net2[order(net2[, "i"], net2[, "p"]), ]
      np <- table(net2[, "p"])
      net2 <- merge(net2, cbind(p = as.numeric(rownames(np)),np = np))
      ## trasnformed network
      net1 <- merge(net2, cbind(j = net2[, "i"], p = net2[, "p"]))
      net1 <- net1[net1[, "i"] != net1[, "j"], c("i", "j","np")]
      net1 <- net1[order(net1[, "i"], net1[, "j"]), ]
      index <- !duplicated(net1[, c("i", "j")])
      net1 <- cbind(net1[index, c("i", "j")])
      net1
    })
    

    So here you get your b without any warning

    > b
      section time i j
    1       a    9 1 2
    2       a    9 2 1
    3       a   12 2 3
    4       a   12 2 4
    5       a   12 3 2
    6       a   12 3 4
    7       a   12 4 2
    8       a   12 4 3
    

    For the second part of the question , do you want to remove duplicated from b?

    b[!duplicated(t(apply(b[3:4], 1, sort))), ]
      section time i j
    1       a    9 1 2
    3       a   12 2 3
    4       a   12 2 4
    6       a   12 3 4
    

    For this part Here I use an answer to this question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following test data frame : test <- read.table(header = TRUE, text
I have a data.frame from this code: my_df = data.frame(read_time = c(2010-02-15, 2010-02-15, 2010-02-16,
I have a data frame of counts by region over time. One row of
I have some irregular data in one column. my.table <-read.table(text=ticker,date,last a,12/20/2011,289295 a,12/21/2011,NA a,12/27/2011,297001 a,12/28/2011,NA
I have a data frame with gaps like this: Var1 Var2 Var3 1 NA
I have a data.frame that looks like this: > head(ff.df) .id pio caremgmt prev
I have a data.frame in R that looks like this: score rms template aln_id
I have a data frame in R that looks like this: > TimeOffset, Source,
I have a list within a data frame (in this example, df$candpct ), and
I have a dataframe with numeric entries like this one test <- data.frame(x =

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.