基于R中特定字符串模式的过滤列

时间:2019-12-09 23:09:12

标签: r text grep

我有70多个列,其中随机字符串名称作为列名称。

   [1] "ID"                                                                            
   [2] "Label_926"                                                                     
   [3] "2010_Invoices_from_DJA"                                                        
   [4] "2469216M3005DAA90_6932_SLC_PARKI"                                              
   [5] "3DE227-101_3DE_"                                                               
   [6] "Total_3DE"                                                                     
   [7] "3FM226-101_3Form_"                                                             
   [8] "Total_3Form"                                                                   
   [9] "5_STAR_NEWS_Number1_0445_DFW_AIRPORT"                                          
  [10] "51COMPANYKITCHEN_877MERRIAM"                                                   
  [11] "7-ELEVEN_29175_00072MURRAY"                                                    
  [12] "8x8_Inc_"                                                                      
  [13] "ACM228-101_A-C_Central_Middle_School_"                                         
  [14] "ACM228-102_A-C_Central_Middle_School_"                                         
  [15] "Total_A-C_Central_Middle_School"                                               
  [16] "AAA_TAXI_0138_090115PHOENIX"                                                   
  [17] "AARP_see_notes_for_new_address_"                                               
  [18] "ACE_PRKING_PS_Number2522_IRVINE"                                               
  [19] "Ad_Hoc_Communications"                                                         
  [20] "AG232-103_Adtalem_"                                                            
  [21] "AG232-104_Adtalem_"

我需要根据名称中的以下条件选择列:

1. Three capital letters at the beginning
2. An immediate dash following the three capital letters
3. Follow the dash by three numbers between 100 and 200
4. End the string at the first "_"

我不明白,或者无法根据条件的顺序让grep()为我工作。在我看来,它只匹配字符串的某些部分。

0 个答案:

没有答案