title: R Cleaning and reordering names/serial numbers in data frame
body: <p>Let's say I have a data frame as follows in R:</p>
  
  <pre><code> Data &lt;- data.frame("SerialNum" = character(), "Year" = integer(), "Name" = character(), stringsAsFactors = F)
   Data[1,] &lt;- c("983\n837\n424\n ", 2015, "Michael\nLewis\nPaul\n ")
   Data[2,] &lt;- c("123\n456\n789\n136", 2014, "Elaine\nJerry\nGeorge\nKramer")
   Data[3,] &lt;- c("987\n654\n321\n975\n ", 2010, "John\nPaul\nGeorge\nRingo\nNA")
   Data[4,] &lt;- c("424\n983\n837", 2015, "Paul\nMichael\nLewis")
   Data[5,] &lt;- c("456\n789\n123\n136", 2014, "Jerry\nGeorge\nElaine\nKramer")
  </code></pre>
  
  <p>What I want to do is the following:</p>
  
  <ol>
  <li>Split up each string of names and each string of serial numbers so that they are their own vectors (or a list of string vectors).</li>
  <li>Eliminate any character <code>"NA"</code> in either set of vectors or any blank spaces denoted by <code>"...\n "</code>.</li>
  <li>Reorder each list of names alphabetically and reorder the corresponding serial numbers according to the same permutation.</li>
  <li>Concatenate each vector in the same fashion it was originally (I usually do this with <code>paste(., collapse = "\n")</code>).</li>
  </ol>
  
  <p>My issue is how to do this without using a for loop.  What is an object-oriented way to do this?  As a first attempt in this direction I originally made a list by the command <code>LIST &lt;- strsplit(Data$Name, split = "\n")</code> and from here I need a for loop in order to find the permutations of the names, which seems like a process that won't scale according to my actual data.  Additionally, once I make the list <code>LIST</code> I'm not sure how I go about removing <code>NA</code> symbols or blank spaces.  Any help is appreciated!</p>