Sample Data
action advertname
aLoad
bServed Leanardo Vertical Tie Horizontal
click Leanardo Vertical Tie Horizontal
aLoad
bServed The Label Vineet
aLoad
aLoad
aLoad
aLoad
bServed Clooney the label
close Clooney the label
aLoad
aLoad
aLoad
bServed Angad Vertical Clooney Horizontal
close Angad Vertical Clooney Horizontal
I need to number Advert name by comparing the before what i actually used in Excel to generate that is IF(Advertname3=Advertname2,Adblk2,Adblk2+1)
action advertname AdBlk aLoad 1 bServed Leanardo Vertical Tie Horizontal 2 click Leanardo Vertical Tie Horizontal 2 aLoad 3 bServed The Label Vineet 4 aLoad 5 aLoad 5 aLoad 5 aLoad 5 bServed Clooney the label 6 close Clooney the label 6 aLoad 7 aLoad 7 aLoad 7 bServed Angad Vertical Clooney Horizontal 8 close Angad Vertical Clooney Horizontal 8
I am working on the click stream data of size more than a million size.I am trying to create the ad number based advert name for sorting purpose as the second is not recorded in time.
ID_Sort[1,24] <- 1
for(i in 2:nrow(ID_Sort))
{
if(ID_Sort[i,14] == ID_Sort[(i-1),14])
{
a <- ID_Sort[(i-1),24]
ID_Sort[i,24] <- a
}
else
{
a <- ID_Sort[(i-1),24]
ID_Sort[i,24] <- a+1
}
}
This code is working fine for sample data with minimum time but taking long time for 1million+ data. So please help me to overcome from this delay. Is there any way rather than FOR loop.