title: R transposing numeric data.frame results in character variables
body: <p>I've got a data.frame which contains a character variable and multiple numeric variables, something like this:</p>
  
  <pre><code>sampleDF &lt;- data.frame(a = c(1,2,3,"String"), b = c(1,2,3,4), c= c(5,6,7,8), stringsAsFactors = FALSE)
  </code></pre>
  
  <p>Which looks like this:</p>
  
  <pre><code>       a b c
  1      1 1 5
  2      2 2 6
  3      3 3 7
  4 String 4 8
  </code></pre>
  
  <p>I'd like to transpose this data.frame and get it to look like this:</p>
  
  <pre><code>  V1 V2 V3     V4
  1  1  2  3 String
  2  1  2  3      4
  3  5  6  7      8
  </code></pre>
  
  <p>I tried </p>
  
  <pre><code>c&lt;-t(sampleDF)
  </code></pre>
  
  <p>as well as</p>
  
  <pre><code>d&lt;-transpose(sampleDF)
  </code></pre>
  
  <p>but both these methods result in V1, V2 and V3 now being of characer type despite only having numeric values.</p>
  
  <p>I know that this has already been asked multiple times. However, I haven't found a suitable answer for why in this case V1, V2 and V3 are also being converted to character.</p>
  
  <p>Is there any way how ensure that these column stay numeric?</p>
  
  <p>Thanks a lot any apologies already for the duplicate nature of this question.</p>
  
  <p>EDIT:</p>
  
  <pre><code>as.data.frame(t(sampleDF)
  </code></pre>
  
  <p>Does not solve the problem:</p>
  
  <pre><code>'data.frame':   3 obs. of  4 variables:
   $ V1: Factor w/ 2 levels "1","5": 1 1 2
    ..- attr(*, "names")= chr  "a" "b" "c"
   $ V2: Factor w/ 2 levels "2","6": 1 1 2
    ..- attr(*, "names")= chr  "a" "b" "c"
   $ V3: Factor w/ 2 levels "3","7": 1 1 2
    ..- attr(*, "names")= chr  "a" "b" "c"
   $ V4: Factor w/ 3 levels "4","8","String": 3 1 2
    ..- attr(*, "names")= chr  "a" "b" "c"
  </code></pre>