title: How to remove part of a string in a column of dataframe in R?
body: <p>I have a dataframe like following:</p>
  
  <pre><code>df:
  
   S            S1       S2     S3       S4   
  100130426     0        0    0.9066     0
  100133144   16.3644  9.2659 11.6228 12.0894
  100134869   12.9316  17.379 9.2294  11.0799
       3457   1910.3  2453.50 2695.37 1372.3624
       9834   1660.13 857.30  1240.53 1434.6463
  ATP5L2|267    0        0     0.9066    0
  ATP5L|1063  1510.29 1270.79 2965.54 2397.1866
  ATP5O|539   2176.17 1868.95 2004.53 2360.3641
  </code></pre>
  
  <p>I actually want to remove "|" and also numbers after "|" in the first column. For eg: ATP5L2|267 should be like ATP5L2.</p>
  
  <p>So I tried in the following way:</p>
  
  <pre><code>SD &lt;- sapply(strsplit(df$s, split='|', fixed=TRUE), function(x) (x[1]))
  </code></pre>
  
  <p>But this gave me an error:</p>
  
  <pre><code>Error in strsplit(s, split = "|", fixed = TRUE) : non-character argument.
  </code></pre>
  
  <p>Output should look like following:</p>
  
  <pre><code>df:
  
   S            S1       S2     S3       S4   
  100130426     0        0    0.9066     0
  100133144   16.3644  9.2659 11.6228 12.0894
  100134869   12.9316  17.379 9.2294  11.0799
       3457   1910.3  2453.50 2695.37 1372.3624
       9834   1660.13 857.30  1240.53 1434.6463
     ATP5L2     0        0     0.9066    0
      ATP5L   1510.29 1270.79 2965.54 2397.1866
      ATP5O   2176.17 1868.95 2004.53 2360.3641
  </code></pre>