Creating a new variable based on prior history
问题 I have data where I need to create a variable based on prior history, for example created<- c(2009,2010,2010,2011, 2012, 2011) person <- c(A, A, A, A, B, B) location<- c('London','Geneva', 'London', 'New York', 'London', 'London') df <- data.frame (created, person, location) I want to create a variable called 'existing' that takes into account the prior years and sees if he/she has lived in that place and gives a value of 0 if the place is old(and they lived there. Any suggestions? library