title: Why does strip.white work when trimws does not?
body: <p>I am reading in a .csv that NA observations are recorded as "-   ". </p>
  
  <pre><code>returns &lt;-read.csv("~/R/ADFG_Obtained_AKReturns.csv", stringsAsFactors = FALSE)
  str(returns)
  
  'data.frame':   4222 obs. of  15 variables:
  $ Year            : int  1975 1976 1977 1977 1977 1977 1977 1978 1978 1978 ...
  $ Region          : chr  "Kodiak &amp; AK Peninsula" "Kodiak &amp; AK Peninsula" "Kodiak &amp; AK Peninsula" "Prince William Sound" ...
  $ Hatchery        : chr  "Kitoi Bay" "Kitoi Bay" "Kitoi Bay" "AF Koernig" 
  ...
   $ Project         : chr  "Kitoi Bay" "Kitoi Bay" "Kitoi Bay" "Port San 
  Juan" ...
   $ Species         : chr  "Pink" "Pink" "Pink" "Pink" ...
   $ Seine           : chr  " -   " " -   " " -   " " 2,000 " ...
   $ Gillnet         : chr  " -   " " -   " " -   " " -   " ...
   $ Troll           : chr  " -   " " -   " " -   " " -   " ...
   $ Other.Commercial: chr  " -   " " -   " " -   " " -   " ...
   $ Sport           : chr  " -   " " -   " " -   " " -   " ...
   $ PersUse         : chr  " -   " " -   " " -   " " -   " ...
   $ Subsis          : chr  " -   " " -   " " -   " " -   " ...
   $ Brood           : chr  " 5,800 " " 8,000 " " -   " " 21,300 " ...
   $ CR.catch        : chr  " -   " " -   " " -   " " 15,545 " ...
   $ Other           : chr  " -   " " -   " " 18,500 " " -   " ...
  </code></pre>
  
  <p>When I read in the .csv then attempt to trimws, the white spaces are not removed (the df does not change at all. This was first attempted by the suggestion of my colleagues' reformatting process). Note that in the below code I used "both", but I've attempted "right" with the same results. </p>
  
  <pre><code>returns &lt;-read.csv("~/R/ADFG_Obtained_AKReturns.csv", stringsAsFactors = FALSE)
  returns &lt;- trimws(returns, which = c("both"))
  str(returns)
  
  'data.frame':   4222 obs. of  15 variables:
  $ Year            : int  1975 1976 1977 1977 1977 1977 1977 1978 1978 
  1978 ...
  $ Region          : chr  "Kodiak &amp; AK Peninsula" "Kodiak &amp; AK 
  Peninsula" "Kodiak &amp; AK Peninsula" "Prince William Sound" ...
  $ Hatchery        : chr  "Kitoi Bay" "Kitoi Bay" "Kitoi Bay" "AF 
  Koernig" ...
  $ Project         : chr  "Kitoi Bay" "Kitoi Bay" "Kitoi Bay" "Port San 
  Juan" ...
  $ Species         : chr  "Pink" "Pink" "Pink" "Pink" ...
  $ Seine           : chr  " -   " " -   " " -   " " 2,000 " ...
  $ Gillnet         : chr  " -   " " -   " " -   " " -   " ...
  $ Troll           : chr  " -   " " -   " " -   " " -   " ...
  $ Other.Commercial: chr  " -   " " -   " " -   " " -   " ...
  $ Sport           : chr  " -   " " -   " " -   " " -   " ...
  $ PersUse         : chr  " -   " " -   " " -   " " -   " ...
  $ Subsis          : chr  " -   " " -   " " -   " " -   " ...
  $ Brood           : chr  " 5,800 " " 8,000 " " -   " " 21,300 " ...
  $ CR.catch        : chr  " -   " " -   " " -   " " 15,545 " ...
  $ Other           : chr  " -   " " -   " " 18,500 " " -   " ...
  </code></pre>
  
  <p>If I use strip.white within the read.csv call, the white spaces are removed. I'm assuming this has something to do with how read.csv works, but looking through the appropriate <a href="http://stat.ethz.ch/R-manual/R-devel/library/utils/html/read.table.html" rel="nofollow noreferrer">R documentation</a> I still don't understand why this is occurring. </p>
  
  <pre><code>returns &lt;-read.csv("~/R/ADFG_Obtained_AKReturns.csv", stringsAsFactors = FALSE, strip.white = TRUE)
  str(returns)
  
  
  'data.frame':   4222 obs. of  15 variables:
  $ Year            : int  1975 1976 1977 1977 1977 1977 1977 1978 1978 
  1978 ...
  $ Region          : chr  "Kodiak &amp; AK Peninsula" "Kodiak &amp; AK 
  Peninsula" "Kodiak &amp; AK Peninsula" "Prince William Sound" ...
  $ Hatchery        : chr  "Kitoi Bay" "Kitoi Bay" "Kitoi Bay" "AF 
  Koernig" ...
  $ Project         : chr  "Kitoi Bay" "Kitoi Bay" "Kitoi Bay" "Port San 
  Juan" ...
  $ Species         : chr  "Pink" "Pink" "Pink" "Pink" ...
  $ Seine           : chr  "-" "-" "-" " 2,000 " ...
  $ Gillnet         : chr  "-" "-" "-" "-" ...
  $ Troll           : chr  "-" "-" "-" "-" ...
  $ Other.Commercial: chr  "-" "-" "-" "-" ...
  $ Sport           : chr  "-" "-" "-" "-" ...
  $ PersUse         : chr  "-" "-" "-" "-" ...
  $ Subsis          : chr  "-" "-" "-" "-" ...
  $ Brood           : chr  " 5,800 " " 8,000 " "-" " 21,300 " ...
  $ CR.catch        : chr  "-" "-" "-" " 15,545 " ...
  $ Other           : chr  "-" "-" " 18,500 " "-" ...
  </code></pre>
  
  <p>So adding the strip.white call does exactly what I would like for the blank ("-") cells, I just don't understand why; and why does trimws not work in this case? </p>
  
  <p>Also, are there still whitespaces remaining on the observations that are numbers? </p>
  
  <pre><code>$ Seine           : chr  "-" "-" "-" " 2,000 " ...
  </code></pre>
  
  <p>For my next step, I will be changing the type from character to numeric with the following code, but would appreciate any suggestions on how to do this for all columns Seine:Other (cols 6:15 in my df).  </p>
  
  <pre><code>returns$Seine &lt;- as.numeric(gsub(",","",returns$Seine))
  
   $ Seine           : num  NA NA NA 2000 NA NA NA NA NA NA ...
  </code></pre>
  
  <p>(FYI, this is the first question I have asked.) </p>