title: How to vectorize R strsplit?
body: <p>When creating functions that use <code>strsplit</code>, vector inputs do not behave as desired, and <code>sapply</code> needs to be used. This is due to the list output that <code>strsplit</code> produces. Is there a way to vectorize the process - that is, the function produces the correct element in the list for each of the elements of the input?</p>
  
  <p>For example, to count the lengths of words in a character vector:</p>
  
  <pre><code>words &lt;- c("a","quick","brown","fox")
  
  &gt; length(strsplit(words,""))
  [1] 4 # The number of words (length of the list)
  
  &gt; length(strsplit(words,"")[[1]])
  [1] 1 # The length of the first word only
  
  &gt; sapply(words,function (x) length(strsplit(x,"")[[1]]))
  a quick brown   fox 
  1     5     5     3 
  # Success, but potentially very slow
  </code></pre>
  
  <p>Ideally, something like <code>length(strsplit(words,"")[[.]])</code> where <code>.</code> is interpreted as the being the relevant part of the input vector.</p>