I have a dataframe from a survey in which users were asked questions across multiple days. I need to create a column which contains an integer equal to what number survey it is for each user. Something like this:
User Survey_Number
1 1
1 2
1 3
1 4
2 1
2 2
3 1
3 2
3 3
4 1
4 2
5 1
How do I increment through each row for each user to assign the value for Survey_Number? This is what I have, though I know it's probably not on the right track. It sets Survery_Number equal to 0 in each row. (Yes, I know I'm bad at this)
for(i in(data.dat$User))
k<-0
for(j in (data.dat$Survey_Number))
data.dat$Survery_Number<-k
k<-(k+1)