2017年9月13日水曜日

use regular expression to pick up multiple columns to meet the criteria.

when columns as below

> names(b2b_mon_xts)
 [1] "SMB.Q"                      "Enterprise.Q"               "B2B.Total.Q"              
 [4] "SMB.Q.New"                  "SMB.Q.Renew"                "Enterprise.Q.New"        
 [7] "Enterprise.Q.Renew"         "SMB.Gross.Bkg"              "Enterprise.Gross.Bkg"    
[10] "B2B.Gross.BkgTotal"         "SMB.Gross.Bkg.New"          "SMB.Gross.Bkg.Renew"      
[13] "Enterprise.Gross.Bkg.New"   "Enterprise.Gross.Bkg.Renew" "SMB.Net.Bkg"              
[16] "Enterprise.Net.Bkg"         "B2B.Net.Bkg.Total"          "New"                      
[19] "Actual"    

use grep and it regular expression to pick up multiple columns to meet the criteria.
            
> b2b_mon_xts[,grep("^New|^Actual",names(b2b_mon_xts))]
           New Actual
2013-01-01 195    111
2013-02-01 344    165
2013-03-01 307    188
2013-04-01 322    223
2013-05-01 238    260
2013-06-01 237    254

0 件のコメント: