Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
economics:r:text-manipulation [2019/05/15 14:50]
Olivier Simard-Casanova [Delete string in a variable]
economics:r:text-manipulation [2019/05/15 14:52] (current)
Olivier Simard-Casanova [Delete string in a variable]
Line 33: Line 33:
  
 `grepl` is used to match a specific string in the variable to process (https://​stat.ethz.ch/​R-manual/​R-devel/​library/​base/​html/​grep.html). `fixed = TRUE` assures that this string is evaluated as text, not as a regular expression. `grepl` is used to match a specific string in the variable to process (https://​stat.ethz.ch/​R-manual/​R-devel/​library/​base/​html/​grep.html). `fixed = TRUE` assures that this string is evaluated as text, not as a regular expression.
 +## Delete everything before a string
 +
 +<​code:​R>​
 +df$var <- gsub("​.*STRING",​ "",​ df$var)
 +</​code>​
 +
 +`STRING` can be a single character, or more.
  
 ## Delete string in a variable ## Delete string in a variable
Line 43: Line 50:
  
 To ignore case, add `ignore.case = TRUE` as a parameter in `gsub`. To ignore case, add `ignore.case = TRUE` as a parameter in `gsub`.
 +
 +
  
 ## Extract strings before a certain character occurs ## Extract strings before a certain character occurs
  • Last modified: 7 days ago
  • by Olivier Simard-Casanova