0

I have a data frame with three columns, the first one is the id, the second one when an event A happend and a third column when the event B happened.

client <- rep(c("A","B","C"),5)
event_a <- c("2017-04-02","2017-04-07","2017-04-10", "2017-04-13","2017-04-
17","2017-04-18","2017-04-20","2017-04-22","2017-04-25","2017-04-27","2017-
04-30","2017-05-10","2017-05-12","2017-05-15","2017-05-20")
event_b <- c("2017-04-05",NA,"2017-04-11", "2017-04-14",NA,"2017-04-
20","2017-04-21",NA,"2017-04-30",NA,"2017-04-30",NA,NA,"2017-05-15",NA)
data <- data.frame(client, event_a, event_b)

I would like to know if the client makes the event A after the event B, or if event B is NA - a boolean variable or a count one. But I like to insert this column in the data.frame, to model in a second moment.

Thank you!

  • Could you give an example of a desired output! – Vitalijs May 25 '17 at 13:42
  • I would like to know if the client return. If the client return to my store, I create another row. So, the function has to find the customer in lines below, but only counts if the new line's event A is greater than the old line. In this example, the output would be: c(1,1,1,1,1,1,1,1,1,1,1,1,0,0,0) – Maximilian Follet May 25 '17 at 14:15

2 Answers2

0

I suppose you want just this

data$logic_value<-!is.na(data$event_b)
Federico Manigrasso
  • 1,130
  • 1
  • 7
  • 11
0
data$indicator <- ifelse((as.numeric(as.POSIXct(data$event_a)) > as.numeric(as.POSIXct(data$event_b)) | is.na(data$event_b)), 1, 0)
klumbard
  • 165
  • 1
  • 7