R coding: How to keep records with 4 complete quarters of data

前端 未结 3 576
囚心锁ツ
囚心锁ツ 2021-01-27 01:07

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

3条回答
  •  -上瘾入骨i
    2021-01-27 01:42

    Here is the code that can help you:

    library(data.table)
    data<-data.table( year, qtr, company, IQ, REVQ, AssetQ, CashQ)
    fullyr <- data[,.(len=.N),by=.(year)][len == 4]
    data <- data[year %in% fullyr$year]
    

    Requesting you to provide the code you have tried for solution next time :)

提交回复
热议问题