title: How do I calculate a percent change of a zoo object using sapply?
body: <p>I have a list of zoo objects. The core data is the adjusted close of several stock symbols, monthly data. Each list object is a separate time series for each ticker. I'd like to calculate the monthly change for each month, in each object. If it helps, here's what gets me up to my desired calculation:</p>
  
  <pre><code>path = 'C:/SectorRotationSymbList072013.csv'
  symbs = read.csv(path, header = FALSE, stringsAsFactors = FALSE)
  symbs = symbs[, 1]
  importData = vector('list', length(symbs))
  
  #Get monthly pricing data.
  for (sIdx in 1:length(symbs)){
      #Import the data for each symbol into the list.
      importData[[sIdx]] = get.hist.quote(instrument= symbs[sIdx],
          start="2000-01-01", end="2013-07-15", quote="AdjClose",
          provider="yahoo", origin="1970-01-01",
          compression="m", retclass="zoo")
  }
  
  names(importData) = symbs
  </code></pre>
  
  <p>I can get the month over month change for each object using sapply as follows:</p>
  
  <pre><code>monthlyGainsLosses = sapply(importData, diff)
  </code></pre>
  
  <p>I want relative change, though (%). I've tried every variation I can think of on the simple calculation, including:</p>
  
  <pre><code>monthlyGainsLosses = sapply(importData, diff / importData)
  monthlyGainsLosses = sapply(importData, diff / coreData(importData))
  </code></pre>
  
  <p>None of which work. For the latter (which seems most logical to me) I get the error:</p>
  
  <p>non- numeric argument to binary operator. Can anyone help?</p>