title: How does one achieve in R SUBSTRING function like the functionality present in SQL
body: <p>I have the following data frame (dput at end of post):</p>
  
  <pre><code>&gt; d2
    a    b     c
  1 1 1111  1111
  2 2 2222  2222
  3 3    3     3
  4 4    4 44444
  5 5    5     5
  6 6    6 66666
  </code></pre>
  
  <p>what I want to do is print the data frame with substring(b,1,2) and length(c). In SQL it would be something like:</p>
  
  <pre><code>select a,substring(b,1,2),length(c) from d2
  </code></pre>
  
  <p>expected output:</p>
  
  <pre><code>  a  b c
  1 1 11 4
  2 2 22 4
  3 3  3 1
  4 4  4 5
  5 5  5 1
  6 6  6 5
  </code></pre>
  
  <p>How do I do that in R?</p>
  
  <pre><code>&gt; dput(d2)
  structure(list(a = c(1, 2, 3, 4, 5, 6), b = structure(1:6, .Label = c("1111", 
  "2222", "3", "4", "5", "6"), class = "factor"), c = structure(1:6, .Label = c("1111", 
  "2222", "3", "44444", "5", "66666"), class = "factor")), .Names = c("a", 
  "b", "c"), row.names = c(NA, -6L), class = "data.frame")
  </code></pre>