title: Sort character in vector of string in R
body: <p>I have data like,</p>
  
  <pre><code>df &lt;- structure(list(Sex = structure(c(1L, 1L, 2L, 1L, 2L, 2L, 1L, 
  2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("F", "M"), class = "factor"), 
      Age = c(19L, 16L, 16L, 13L, 16L, 30L, 16L, 30L, 16L, 30L, 
      30L, 16L, 19L, 1L, 30L), I = c(1, 1, 0, 0, 1, 0, 1, 0, 1, 
      0, 0, 0, 1, 0, 1), E = c(0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 
      1, 0, 1, 0), S = c(1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 
      0, 1), N = c(0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0), 
      F = c(1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1), T = c(0, 
      1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0), C = c(1, 1, 1, 
      0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1), D = c(0, 0, 0, 1, 0, 
      1, 0, 1, 0, 1, 1, 1, 1, 0, 0), type = c("CIFS", "CITN", "CESF", 
      "DEFS", "CIFN", "DETS", "CITS", "DEFS", "CIFN", "DEFN", "DETS", 
      "DETS", "DINF", "CENT", "CIFS"), PO = runif(15, -3, 3), AO = runif(15, -3, 3)), .Names = c("Sex", 
  "Age", "I", "E", "S", "N", "F", "T", "C", "D", "type", "PO", 
  "AO"), class = c("tbl_dt", "tbl", "data.table", "data.frame"), row.names = c(NA, 
  -15L))
  </code></pre>
  
  <p>I want to sort the column <code>type</code>. Not the column but the characters in it. And get the same structure afterwards. For example, <code>CIFS</code> should then be <code>CFIS</code>. I tried to do it as,</p>
  
  <pre><code>df &lt;- within(df, {
      type &lt;- apply(sapply(strsplit(df[, type], split=''), sort), 2, 
          function(x) paste0(x, collapse = ''))
  })
  </code></pre>
  
  <p>Is there any simpler solution, that I have missed to find.</p>