title: How to understand the output of using gsub on a data.frame
body: <p>Can you use <code>gsub</code> on a data.frame?</p>
  
  <pre><code>dat="1   1W   16   2W   16
  2    1   16   2W    W
  3   1W   16   16    0
  4    4   64   64    0"      
  data=read.table(text=dat,header=F)
  gsub("W",3,data)
  </code></pre>
  
  <p>Why we get an output such as below:</p>
  
  <pre><code>[1] "1:4"               "c(2, 1, 2, 3)"     "c(16, 16, 16, 64)" "c(2, 2, 1, 3)"     "c(2, 3, 1, 1)"   .
  </code></pre>
  
  <p>It is hard to understand.</p>
  
  <pre><code>&gt; str(data)
  'data.frame':   4 obs. of  5 variables:
   $ V1: int  1 2 3 4
   $ V2: Factor w/ 3 levels "1","1W","4": 2 1 2 3
   $ V3: int  16 16 16 64
   $ V4: Factor w/ 3 levels "16","2W","64": 2 2 1 3
   $ V5: Factor w/ 3 levels "0","16","W": 2 3 1 1
  </code></pre>
  
  <p>What is the meaning of the *<em>2 1 2 3 *</em> in  <code>V2: Factor w/ 3 levels "1","1W","4": 2 1 2 3</code>? </p>