How to extract a vector by 100+ unique character strings without having to type all of them by hand in R -


i have data set of more 86,000 different rows , 27 variables. list of different individuals, company, percentage attendance, among other things. each company has data 2010-2011 starting in september way 2015-2016.

a portion of data set below omissions , ellipses indicate transitions.

yr      company month mo    % attendance    %change 2010-11 "015jk" 1    sep    88.21    2010-11 "015jk" 2    oct    92.51             4.31 2010-11 "015jk" 3    nov    90.97            -1.54 2010-11 "015jk" 4    dec    89.19            -1.78 2010-11 "015jk" 5    jan    86.88            -2.31 2010-11 "015jk" 6    feb    89.28             2.4 

...

yr        company  month mo % attendance     %change 2015-2016  015jk    1   jan   82     2015-2016  015jk    2   feb   64               -18 2015-2016  015jk    3   mar   94                30 2015-2016  015jk    4   april 98                4 2015-2016  015jk    5   may   50                -48 2015-2016  015jk    6   june  68                18 

this typical set of data whereupon start again time start new company such:

yr           company    month   mo    %attendance          %change 2010-2011    0184jk     1       jan     49   2010-2011    0184jk     2       feb     52                   3 2010-2011    0184jk     3       mar     82                   30 2010-2011    0184jk     4       april   55                  -27 2010-2011    0184jk     5       may     53                   -2 2010-2011    0184jk     6       june    80                   27 

...

yr           company    month   mo     %attendance      %change 2015-2016    0184jk      1      jan        87    2015-2016    0184jk      2      feb        47              -40 2015-2016    0184jk      3      mar        61               14 2015-2016    0184jk      4      april      78               17 2015-2016    0184jk      5      may        43              -35 2015-2016    0184jk      6     june        85               42 

i can capture these sets of data relatively massive 86,000 row datasheet following r codes

015jk <- df[ which( df$company== "015j"), ] 0184jk <- df[ which( df$company== "0184jk"), ] 

the problem that have more 100 plus companies , onerous type in 90+ iterations of

some company name such 015jk <-df[ which(df$company== "some company       name"), ] 

is there way extract unique values of company , input multiple iterations of following aforementioned variety:

some company code name such 015jk <-df[ which(df$company== "some company       code"), ] 


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -