I have a dataframe with company quarterly data and have this question:
How can I retain records for only those companies with 4 quarters of data (as companies sometimes
The following code can help you ....
final=data.frame() for(i in unique(data$company)){ temp=data[data$company==i,] for(j in unique(temp$year)){ if(nrow(temp[temp$year==j,])==4) final=rbind(final,data.frame(company=i,Year=j)) } }
'final' dataframe will contain your required fields.