0

I have a dataset D2 containing total volume of issuances of a financial product by company by month.

  Company    month      Volume
   AWK    2013-01     24244000
   AWK    2013-02     12294000
   AWK    2013-03     17254000
   AWK    2013-04     13939000
   AWK    2013-05     38757000
   AWK    2013-06     34600000
   AWK    2013-08     25240000

I would like to filter out companies that have traded less than 8 months per year in average.

When a company has not traded on a specific month, D2 does not contain any information and D2$month goes directly to the next month.

0

1 Answer 1

2

With dplyr you can summarize by year the times some firm appears and then filter by the condition you want, as following:

library(dplyr)
Data %>% 
        mutate(Count= 1)%>% 
        mutate(Year = substr(month,1,4))%>% group_by(Year, Company)%>%
        summarise(TotalByYear=sum(Count)) %>% filter(TotalByYear<8)
# A tibble: 1 x 3
# Groups:   Year [1]
  Year  Company TotalByYear
  <chr> <chr>         <dbl>
1 2013  AWK               7
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.