I have the following data frame NewTests: The problem: I want to replicate the rows in the data frame using the information in 'duration' column. Although in this case the replication factor is 1 but it can be anything 2,3,4, etc. And in the replicate rows I want to add a new column called as 'Date' which contains information from the PromotionStartDate and PromotionEndDate columns.
E.g. in this case, the Date Column should contain 2017-04-01 for the entries shown. But in another case where duration is 2 and the PromotionStartDatae= 2017-03-01 and PromotionEndDate=2017-05-01, the replicated row 1 should contain 2017-03-01 in Date column and the replicated row 2 should contain 2017-04-01 in Date column.
I am trying to use the following solution to work out my problem:
library(splitstackshape)
newConrtols=expandRows(NewTests,"duration",drop=FALSE)%>%
group_by(CustomerNumber,PromotionID,RewardAssigned,RunID,ModelID)%>%
mutate(Date=seq(as.Date(PromotionStartDate),as.Date(PromotionEndDate),by="month")[1:duration])
But this gives the error:
Error in mutate_impl(.data, dots) : 'from' must be of length 1
What am I doing wrong in the solution?