title: Converting number scale into category
body: <p>I have a data frame that looks like this:</p>
  
  <pre><code>&gt; example
                              Country Urban
  1                       Afghanistan     0
  2                           Albania    40
  3                           Algeria    50
  4                           Andorra    50
  5                            Angola    60
  6               Antigua and Barbuda    32
  7                         Argentina    60
  8                           Armenia    90
  9                         Australia    50
  10                          Austria    50
  11                       Azerbaijan    60
  12                          Bahrain    60
  13                       Bangladesh     0
  14                         Barbados    80
  15                          Belarus    60
  16                          Belgium    50
  17                           Belize    40  
  18                            Benin      
  19                           Bhutan    30
  20 Bolivia (Plurinational State of)    40
  </code></pre>
  
  <p>I wanted to categorize number scales (0-49) as 2. So, after getting rid of the blank rows, I tried:</p>
  
  <pre><code>example &lt;- as.data.frame(sapply(example, gsub, pattern = c(0:49), replacement = 2))
  </code></pre>
  
  <p>It didn't work.</p>
  
  <p>Here is the reproducible sample generated using dput:</p>
  
  <pre><code>structure(list(Country = structure(1:20, .Label = c("Afghanistan", 
  "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", 
  "Argentina", "Armenia", "Australia", "Austria", "Azerbaijan", 
  "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", 
  "Benin", "Bhutan", "Bolivia (Plurinational State of)"), class = "factor"), 
      Urban = structure(c(2L, 7L, 12L, 12L, 14L, 5L, 14L, 19L, 
      12L, 12L, 14L, 14L, 2L, 18L, 14L, 12L, 8L, 1L, 4L, 7L), .Label = c("", 
      "0", "100", "30", "32", "35", "40", "40  ", "45", "48", "48  ", 
      "50", "56  ", "60", "64  ", "65", "70", "80", "90"), class = "factor")), .Names = c("Country", 
  "Urban"), row.names = c(NA, 20L), class = "data.frame")
  </code></pre>