title: how do you extract the columns that contain a certain text/string in R
body: <p>I need to be able to extract columns that contain exact string that I am looking for. For example, I have this data frame x:</p>
  
  <pre><code>structure(list(Time = structure(1L, .Label = "1/1/2015", class = "factor"), 
      WTAD..Linux..Linux.Percent.of.Physical.Memory.and.Swap.Used.on.web02.Total.Phys.Mem.MB. = 3555L, 
      WTAD..Linux..Linux.Percent.of.Physical.Memory.and.Swap.Used.on.web02.Total.Phys.Mem.Free.MB. = 55L, 
      WTAD..Linux..Linux.Percent.of.Physical.Memory.and.Swap.Used.on.web02.Total.Swap.Free.MB. = 44L, 
      WTAD..Linux..Linux.Percent.of.Physical.Memory.and.Swap.Used.on.web02.Total.Cache.Free.MB. = 66L, 
      WTAD..Linux..Linux.Percent.of.Physical.Memory.and.Swap.Used.on.web02.Total.Swap.And.Cache.Free.MB. = 44L, 
      WTAD..Linux..Linux.Percent.of.Physical.Memory.and.Swap.Used.on.web02.Total.Percent.Free = 44L, 
      WTAD..Linux..Linux.Percent.of.Physical.Memory.and.Swap.Used.on.web02.Round.Trip.Time = 44L), .Names = c("Time", 
  "WTAD..Linux..Linux.Percent.of.Physical.Memory.and.Swap.Used.on.web02.Total.Phys.Mem.MB.", 
  "WTAD..Linux..Linux.Percent.of.Physical.Memory.and.Swap.Used.on.web02.Total.Phys.Mem.Free.MB.", 
  "WTAD..Linux..Linux.Percent.of.Physical.Memory.and.Swap.Used.on.web02.Total.Swap.Free.MB.", 
  "WTAD..Linux..Linux.Percent.of.Physical.Memory.and.Swap.Used.on.web02.Total.Cache.Free.MB.", 
  "WTAD..Linux..Linux.Percent.of.Physical.Memory.and.Swap.Used.on.web02.Total.Swap.And.Cache.Free.MB.", 
  "WTAD..Linux..Linux.Percent.of.Physical.Memory.and.Swap.Used.on.web02.Total.Percent.Free", 
  "WTAD..Linux..Linux.Percent.of.Physical.Memory.and.Swap.Used.on.web02.Round.Trip.Time"
  ), class = "data.frame", row.names = c(NA, -1L))
  </code></pre>
  
  <p>I need to only extract the column that contains this exact match ".Total.Phys.Mem.MB."</p>
  
  <p>When I do this:</p>
  
  <pre><code>x[,grepl(".Total.Phys.Mem.MB.", colnames(x)[2:ncol(x)])]
  </code></pre>
  
  <p>I dont get the column that contains this string in it ".Total.Phys.Mem.MB.". Is there a better way to extract the columns that contain the string in R?</p>