jeudi 14 mars 2019

R Assigning New Variable based on data

I have a data which includes rentals and searchs. If search is made by same customer who made rental, and if search made before rental then i want to assign as successful search.

Here is a part of my data.

time <- c("2019-03-13 14:43:00", "2019-03-13 14:34:00", "2019-03-13 14:23:00")
user <- c("A", "B", "A")
Type <- c("Rental","Search","Search")
data <- cbind(time, user, Type)

I need a new column that shows third row as successful.

But I have lots of data. So i need to do something like this:

  • If type is search and
  • If there is a rental up to 2 hours after search,
  • And if that rental's user name is equals search's user name

Then data$result <- "Successful"

Aucun commentaire:

Enregistrer un commentaire