title: Trim Off Varying Last Special Characters in R
body: <p>Below is a gsub approach for trimming off forward slashes from a data frame. Looking to find a more general solution for data.frame's with varying column counts.</p>
  
  <pre><code>helloToday &lt;- data.frame(a = c("hello", "hello", "hello"), 
                   b = c("world","","world"),
                   c = c("","","today"))
  
  helloToday
  #      a     b     c
  # 1 hello world      
  # 2 hello            
  # 3 hello world today  
  
  
  # Returns the vector 
  helloToday &lt;- apply(helloToday, 1, function(x){ paste0("/", paste(x, collapse = "/")) })
  # [1] "/hello/world/"      "/hello//"           "/hello/world/today"
  
  # But I would like the trailing symbols to be trimmed off
  # [1] "/hello/world"      "/hello"           "/hello/world/today"
  
  
  gsub("\\/$", "", gsub("\\/$", "", helloToday))
  # "/hello/world/"      "/hello//"           "/hello/world/today"
  
  helloToday &lt;- gsub("\\//$", "", helloToday)
  helloToday &lt;- gsub("\\/$", "", helloToday)
  # "/hello/world/"      "/hello//"           "/hello/world/today"
  </code></pre>
  
  <p>Is there a solution which would allow varying column counts, where "/" or "//" or even "///////////"?</p>