0

I have a table that consists of only columns of type Date. The data is about shopping behavior of customers on a website. The columns correspond to the first time an event is triggered by a customer (NULL if no occurrence of the event). One of the columns is the purchase motion.

I want to update the table so that all the for a particular row, all the cells that do did not happen 7 days prior to the purchase are replaced with NULL. I'm looking for some guidance in coding this single line. I've tried utilizing mutate_all() to no avail.

alexT
  • 49
  • 5

1 Answers1

0

Assuming your data is called df, date columns start with date_ and the purchase date is purchase_date, perhaps something like this?

mutate(
  df,
  across(starts_with(“date_”),
  ~ifelse(purchase_date - . < -7, 
    NA, 
    .))
   )