-1

I have the following vector of character strings:

v<-c("RT @name1: hello world", "Hi guys, how are you?", "Hello RT I have no text", "RT @name2: Hello!")

I would like to delete only those RT that are positioned at the beginning of strings and store the results in another vector, e.g., w:

> w
 "@name1: hello world"    "Hi guys, how are you?"     "Hello RT I have no text"     "@name2: Hello!"

Maybe I could use function str_extract_all from the package stringr, but I can't apply it to my problem.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Mark
  • 1,577
  • 16
  • 43

2 Answers2

1

Use gsub and the 'anchor' ^, which signifies the beginning of a string:

w <- gsub("^RT\\s", "", v)
Chris Ruehlemann
  • 20,321
  • 4
  • 12
  • 34
0
<-  str_replace(v,"^RT","")