title: Spark Dataframe column with last character of other column
body: <p>I'm looking for a way to get the last character from a string in a dataframe column and place it into another column.</p>
  
  <p>I have a Spark dataframe that looks like this:</p>
  
  <pre><code>    animal
      ======
      cat
      mouse
      snake
  </code></pre>
  
  <p>I want something like this:</p>
  
  <pre><code>    lastchar
      ========
      t
      e
      e
  </code></pre>
  
  <p>Right now I can do this with a UDF that looks like:</p>
  
  <pre><code>    def get_last_letter(animal):
          return animal[-1]
  
      get_last_letter_udf = udf(get_last_letter, StringType())
  
      df.select(get_last_letter_udf("animal").alias("lastchar")).show()
  </code></pre>
  
  <p>I'm mainly curious if there's a better way to do this without a UDF. Thanks!</p>