I have a dataframe with information on individual id, period and code of work place. I would like to know who are the individuals who have worked alone for the entire time span of the dataset.
Consider the very simple example below. Individual A worked alone at two work places (x,y) in period 1. Individual B and C worked together at work place z in period 1. Individual B worked alone at work place w in period 2. Individual D worked alone at place k in period 2.
mydf <- data.frame(id=c('A','A','B','C','B','D'),
period=c(1,1,1,1,2,2),
work_place=c('x','y','z','z','w','k'))
I would like to identify the rows concerning those who have worked alone for the entire period, which in this case are those referring individuals A and D.
ids_alone <- data.frame(id=c('A','A','D'),
period=c(1,1,2),
work_place=c('x','y','k'))