0

I'm having trouble adding the next date value from a column to the same row as the first date, if that makes sense. Each 'event' has a start date and an end date, both contained within a date column. I want to take the next date for a given 'event' ("Well_ID" column) and put it in the Lead_Date column so I can select data between those dates. The following doesn't give errors, but it won't populate the Lead_Date column, and I'm not sure why.

library(dplyr)
library(lubridate)
library(randomForest)
library(stringr)
library(caTools)

# Map 1-based optional input ports to variables
dataset1 <- maml.mapInputPort(1) # class: data.frame

  dataset1 %>% group_by(Well_ID)
  
  dataset1$Lead_Date <- ""
    
  # Add a column of the next event for each Well_ID:
  dataset1 %>% mutate(Lead_Date = lead(Date, order_by = Date))

I'm very new to R, so any help is greatly appreciated!

3
  • 1
    I think you may have a misunderstanding of how the pipe operator (%>%) works. For instance, the group_by call will not carry over to the next call. Also, the beauty of mutate is that you no longer need to create a placeholder column before hand (dataset1$Lead_Date <- "") Jun 11, 2018 at 19:34
  • It would also be helpful if we had example data to work with. You can add some sample data to this question by using the results from dput Jun 11, 2018 at 19:46
  • I've realized that the group_by function isn't working in Azure ML, and that's a source of the error. I got it to work by not using mutate, which also seems to not work properly in Azure ML. Jun 12, 2018 at 21:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.