title: Use strsplit to get last character in r
body: <p>I have a file of baby names that I am reading in and then trying to get the last character in the baby name.  For example, the file looks like..</p>
  
  <pre><code>Name      Sex 
  Anna      F
  Michael   M
  David     M
  Sarah     F
  </code></pre>
  
  <p>I read this in using </p>
  
  <pre><code>sourcenames = read.csv("babynames.txt", header=F, sep=",")
  </code></pre>
  
  <p>I ultimately want to end up with my result looking like..</p>
  
  <pre><code>Name   Last Initial   Sex
  Michael  l             M
  Sarah    h             F
  </code></pre>
  
  <p>I've managed to split the name into separate characters..</p>
  
  <pre><code>sourceout = strsplit(as.character(sourcenames$Name),'')
  </code></pre>
  
  <p>But now where I'm stuck is how to get the last letter, so in the case of Michael, how to get 'l'.  I thought tail() might work but its returning the last few records, not the last character in each Name element.</p>
  
  <p>Any help or advice is greatly appreciated.</p>
  
  <p>Thanks :) </p>