I have data as follows and I want to create new variable that takes into account the preceding information in the prior period. For example,
moviewatched<- c('Comedy', 'Horror', 'Comedy', 'Horror', 'Drama', 'Comedy', 'Drama')
name<- c('john', 'john', 'john', 'john', 'john','kate','kate')
time<- c('1-2018', '1-2018', '1-2018', '2-2018', '2-2018','1-2018' ,'2-2018')
df<- data.frame(moviewatched, name, time)
Now I need to create a variable that will tell what are the new type of genre movies he/she watched in that month. For example, in the above case, John watched 2 genre types in the first month of 2018 and watched 1 new additional type in second month(as he has already watched comedy and horror in the first month).Is there any way I can create a running count of the new types that person started watching? I want to create a variable called movietypewatched that contains total of the all genre types that person watched till that month. The output expected is as follows:
name time movietypewatched
john 1-2018 2
john 2-2018 3
kate 1-2018 1
kate 2-2018 2
Thanks