title: Iterating a function through different columns of a data.frame matching a pattern in the column names
body: <p>I want to iterate a function through different columns (with a common pattern in the column names) of a data.frame. 
  for subsetting the data.frame I use this code that works:</p>
  
  <pre><code>df[,grep("abc", colnames(df))]
  </code></pre>
  
  <p>but I don't know how to apply my function f(x) to all the columns that match this pattern, either using a for loop or lapply function.</p>
  
  <p>the function I'm using is:</p>
  
  <pre><code>compress= function(x) {
    aggregate(df[,x,drop=FALSE],
          list(hour = with(df,paste(dates(Time),
                                           sprintf("%d:00:00",hours(Time))))),
          sum,na.rm=TRUE)
  }
  </code></pre>
  
  <p>where df (the data frame) and Time could be set as variables themselves but for the moment I don't need to do it.</p>
  
  <p>Thanks
  Giulia</p>