Answers.Body: <p>Following gringer's advice I am also adding this solution:</p>
  <p>Used gsub to section off characters in a string.</p>
  <p>My command for this was: <code>gsub(&quot;.*=&quot;,&quot;\\1&quot;,df$SVLEN_INFO)</code></p>
  <p>Thanks for all the help!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-17T18:36:08.137Z
Answers.Text: Does this work? You're using a backreference (`\1`) without a capture group (like `(.*)`), which usually does not work. Also, please use code formatting to format your post properly, I've done it for you this time.
Answers.UserDisplayName: Ram RS
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-17T18:38:40.973Z
Answers.Text: I checked, this only works because `"\\1"` is empty since you don't have a capture group. Just use `""` instead of `"\\1"`. Otherwise, this is NOT a good solution as you're essentially using a bug.
Answers.UserDisplayName: Ram RS
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-17T19:07:42.380Z
Answers.Text: worked for me at the time but again the answer above worked as well...so I'll use that to format moving forward...
Answers.UserDisplayName: rimo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-18T13:41:38.900Z
Answers.Text: Worked for you because it's a bug. If they fix the bug, it will stop working. Many reg-ex based tools error out or behave differently if you use backreferences without capture groups. IIRC `sed` retains the whole matched expression as the default backreference. Use predictable tools predictably instead of depending on bugs to hack your way through problems.
Answers.UserDisplayName: Ram RS
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-17T17:58:28.593Z
Answers.LastActivityDate: 2023-05-17T18:36:14.880Z
Answers.LastEditDate: 2023-05-17T18:36:14.880Z
Answers.UserDisplayName: rimo
Answers.Body: <p>Adding an answer for now:</p>
  <p>You can use <code>sub</code> to remove the <code>SVLEN=</code> part. You don't need <code>gsub</code> and you don't need regular expressions, let alone capture groups.</p>
  <pre class="lang-r prettyprint-override"><code>df$SVLEN_INFO &lt;- sub(x = df$SVLEN_INFO, pattern = &quot;SVLEN=&quot;, replacement = &quot;&quot;)
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-11T13:31:32.507Z
Answers.Text: This is a good answer @rimo
Answers.UserDisplayName: M__
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-17T17:57:11.993Z
Answers.Text: this worked great! thank you
Answers.UserDisplayName: rimo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-11T12:12:14.560Z
Answers.LastActivityDate: 2023-05-11T17:59:58.467Z
Answers.LastEditDate: 2023-05-11T17:59:58.467Z
Answers.UserDisplayName: Ram RS
Body: <p>One of the columns in my R data frame looks like this:</p>
  <pre class="lang-r prettyprint-override"><code>[1] &quot;SVLEN=1007&quot;   &quot;SVLEN=.&quot;      &quot;SVLEN=.&quot;      &quot;SVLEN=.&quot;      &quot;SVLEN=204&quot;    &quot;SVLEN=-379&quot;  
   [7] &quot;SVLEN=-492&quot;   &quot;SVLEN=-825&quot;   &quot;SVLEN=-713&quot;   &quot;SVLEN=.&quot;      &quot;SVLEN=3553&quot;   &quot;SVLEN=432391&quot;
  [13] &quot;SVLEN=.&quot;      &quot;SVLEN=-52&quot;    &quot;SVLEN=&gt;1615&quot;  &quot;SVLEN=.&quot;      &quot;SVLEN=6899&quot;   &quot;SVLEN=.&quot;     
  [19] &quot;SVLEN=.&quot;      &quot;SVLEN=4468&quot;   &quot;SVLEN=.&quot;      &quot;SVLEN=.&quot;      &quot;SVLEN=.&quot;      &quot;SVLEN=627&quot;   
  [25] &quot;SVLEN=.&quot;      &quot;SVLEN=.&quot;      &quot;SVLEN=.&quot;      &quot;SVLEN=1171&quot;   &quot;SVLEN=.&quot;      &quot;SVLEN=625&quot;   
  [31] &quot;SVLEN=.&quot;      &quot;SVLEN=.&quot;      &quot;SVLEN=-237&quot;   &quot;SVLEN=.&quot;      &quot;SVLEN=.&quot;      &quot;SVLEN=-30&quot;   
  [37] &quot;SVLEN=39&quot;     &quot;SVLEN=.&quot;      &quot;SVLEN=-30&quot;    &quot;SVLEN=-377&quot;   &quot;SVLEN=120497&quot; &quot;SVLEN=.&quot;     
  </code></pre>
  <p>and I would like it to look like this:</p>
  <pre><code>[1] &quot;1007&quot;   &quot;.&quot;      &quot;.&quot;      &quot;.&quot;      &quot;204&quot;    &quot;-379&quot;  
   [7] &quot;-492&quot;   &quot;-825&quot;   &quot;-713&quot;   &quot;.&quot;      &quot;3553&quot;   &quot;432391&quot;
  [13] &quot;.&quot;      &quot;-52&quot;    &quot;&gt;1615&quot;  &quot;.&quot;      &quot;6899&quot;   &quot;.&quot;     
  [19] &quot;.&quot;      &quot;4468&quot;   &quot;.&quot;      &quot;.&quot;      &quot;.&quot;      &quot;627&quot;   
  [25] &quot;.&quot;      &quot;.&quot;      &quot;.&quot;      &quot;1171&quot;   &quot;.&quot;      &quot;625&quot;   
  [31] &quot;.&quot;      &quot;.&quot;      &quot;-237&quot;   &quot;.&quot;      &quot;.&quot;      &quot;-30&quot;   
  [37] &quot;39&quot;     &quot;.&quot;      &quot;-30&quot;    &quot;-377&quot;   &quot;120497&quot; &quot;.&quot;         
  </code></pre>
  <p>I could go in to the excel file I got it from and edit it but is there an easy way to do this in R?</p>
  <p><strong>ANSWER</strong>:</p>
  <p>I found a solution to this probelm going back to the R documentation (<a href="https://www.statology.org/gsub-r/" rel="nofollow noreferrer">https://www.statology.org/gsub-r/</a>) use <code>gsub</code> to section off characters in a string. My command for this was: <code>gsub(&quot;.*=&quot;,&quot;\\1&quot;,df$SVLEN_INFO)</code></p>
  <p>And that worked!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-10T20:08:39.943Z
Comments.Text: Instead of adding that extra section to the question, can you please create an answer and put it there? It'll help the StackExchange algorithms to do the right things.
Comments.UserDisplayName: gringer
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-11T13:38:02.493Z
Comments.Text: Can you check the `\\1`? I'm not an R expert but you need brackets for `\\1` to work, otherwise just use `''` as the replace term not with brackets. Thus it should be `gsub(".*=(.*)","\\1",df$SVLEN_INFO)`. Alternatively `gsub(".*=(-?\d+)","\\1",df$SVLEN_INFO)` might work better, not sure. I don't know how type casting works in R. @RamRS has a simple solution.
Comments.UserDisplayName: M__
Tags: <r><dataframe>
Title: editing dataframe in r
ThreadText: # editing dataframe in r
  
  (Asked by: username_0 on 2023-05-10)
  
  One of the columns in my R data frame looks like this:
  
  ```r
  [1] "SVLEN=1007"   "SVLEN=."      "SVLEN=."      "SVLEN=."      "SVLEN=204"    "SVLEN=-379"  
   [7] "SVLEN=-492"   "SVLEN=-825"   "SVLEN=-713"   "SVLEN=."      "SVLEN=3553"   "SVLEN=432391"
  [13] "SVLEN=."      "SVLEN=-52"    "SVLEN=>1615"  "SVLEN=."      "SVLEN=6899"   "SVLEN=."     
  [19] "SVLEN=."      "SVLEN=4468"   "SVLEN=."      "SVLEN=."      "SVLEN=."      "SVLEN=627"   
  [25] "SVLEN=."      "SVLEN=."      "SVLEN=."      "SVLEN=1171"   "SVLEN=."      "SVLEN=625"   
  [31] "SVLEN=."      "SVLEN=."      "SVLEN=-237"   "SVLEN=."      "SVLEN=."      "SVLEN=-30"   
  [37] "SVLEN=39"     "SVLEN=."      "SVLEN=-30"    "SVLEN=-377"   "SVLEN=120497" "SVLEN=."     
  
  ```
  
  and I would like it to look like this:
  
  ```
  [1] "1007"   "."      "."      "."      "204"    "-379"  
   [7] "-492"   "-825"   "-713"   "."      "3553"   "432391"
  [13] "."      "-52"    ">1615"  "."      "6899"   "."     
  [19] "."      "4468"   "."      "."      "."      "627"   
  [25] "."      "."      "."      "1171"   "."      "625"   
  [31] "."      "."      "-237"   "."      "."      "-30"   
  [37] "39"     "."      "-30"    "-377"   "120497" "."         
  
  ```
  
  I could go in to the excel file I got it from and edit it but is there an easy way to do this in R?
  
  **ANSWER**:
  
  I found a solution to this probelm going back to the R documentation (<https://www.statology.org/gsub-r/>) use `gsub` to section off characters in a string. My command for this was: `gsub(".*=","\\1",df$SVLEN_INFO)`
  
  And that worked!
  
  **Tags:** r, dataframe
  
  > **Comments:**
  > **username_1**: Instead of adding that extra section to the question, can you please create an answer and put it there? It'll help the StackExchange algorithms to do the right things.  
  > **username_2**: Can you check the `\\1`? I'm not an R expert but you need brackets for `\\1` to work, otherwise just use `''` as the replace term not with brackets. Thus it should be `gsub(".*=(.*)","\\1",df$SVLEN_INFO)`. Alternatively `gsub(".*=(-?\d+)","\\1",df$SVLEN_INFO)` might work better, not sure. I don't know how type casting works in R. @username_3 has a simple solution.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2023-05-11. Score: 2 | Accepted answer
  
  Adding an answer for now:
  
  You can use `sub` to remove the `SVLEN=` part. You don't need `gsub` and you don't need regular expressions, let alone capture groups.
  
  ```r
  df$SVLEN_INFO <- sub(x = df$SVLEN_INFO, pattern = "SVLEN=", replacement = "")
  
  ```
  
  > **Comments:**
  > **username_2**: This is a good answer @username_0  
  > **username_0**: this worked great! thank you  
  
  ---
  
  ### Answer by username_0 on 2023-05-17. Score: -1
  
  Following username_1's advice I am also adding this solution:
  
  Used gsub to section off characters in a string.
  
  My command for this was: `gsub(".*=","\\1",df$SVLEN_INFO)`
  
  Thanks for all the help!
  
  > **Comments:**
  > **username_3**: Does this work? You're using a backreference (`\1`) without a capture group (like `(.*)`), which usually does not work. Also, please use code formatting to format your post properly, I've done it for you this time.  
  > **username_3**: I checked, this only works because `"\\1"` is empty since you don't have a capture group. Just use `""` instead of `"\\1"`. Otherwise, this is NOT a good solution as you're essentially using a bug.  
  > **username_0**: worked for me at the time but again the answer above worked as well...so I'll use that to format moving forward...  
  > **username_3**: Worked for you because it's a bug. If they fix the bug, it will stop working. Many reg-ex based tools error out or behave differently if you use backreferences without capture groups. IIRC `sed` retains the whole matched expression as the default backreference. Use predictable tools predictably instead of depending on bugs to hack your way through problems.  
  
  ---
  
  