I am trying to calculate the purchase cycle which should be based on two if conditions when true and when any one is false it should increment the row to go to next. This is the R code I am trying to write but this is not working. can someone guide how to get this done.
j=2
k=1
l=1
a<-as.vector(nrow(data))
for (i in 1:a)
{
if(data$HM[k]=data$HM[k+1])
{
if(data$Y[l]=data$Y[k+1])
{
data$purchase_cycle[j]<-data$week[i+1]-data$week[i]
j=j+1
}else{
l=l+1}
}else{
k=k+1}
}
Aucun commentaire:
Enregistrer un commentaire