I have list of company codes(say, this dataframe is called b), which has about 130 companies. In another dataframe(this dataframe is called bb), each column is a company's performance. The name for a centain company's column is just that company's code.
I want to extract each company's performance and put these information into a separate dataframe. I am thinking about creating a foreach to refer each company code in b, then do the extraction.
Following is the example for b and bb
>b
12572 37540 25658 99999 19682 10111 15024 19232 24953 23779 14834 25143 23035 16578 19933 18988 14168 18325 38148 17558 36560 ...
>bb
year ZIP1 month COMPANY_CD marketshare%
2000 10003 1 12572 10
2000 10003 1 37540 20
2000 10003 1 25658 10
2000 10003 1 19682 10
...
2000 10005 1 12572 8
2000 10005 1 23779 8
2000 10005 1 14834 8
...
2001 10003 1 12572 20
2001 10003 1 17558 20
2001 10003 1 25143 20
a is the target dataframe for each company.
>a
year ZIP1 month COMPANY_CD marketshare%
2000 10003 1 12572 10
2000 10005 1 12572 8
...
2001 10003 1 12572 20
Pseudo code is:
a <- bb %>% filter(COMPANY_CD == "12572")%>% select(year,month,`marketshare%`) %>% arrange(year,month,ZIP1)
names(a) <- c("year","month","ZIP1","12572")