我有以下字符串向量:
v<-c("RT @name1: hello world", "Hi guys, how are you?", "Hello RT I have no text", "RT @name2: Hello!")
我只想删除位于字符串开头的RT
并将结果存储在另一个向量中,例如w
:
> w
"@name1: hello world" "Hi guys, how are you?" "Hello RT I have no text" "@name2: Hello!"
也许我可以使用软件包str_extract_all
中的函数stringr
,但不能将其应用于问题。
答案 0 :(得分:1)
使用gsub
和'anchor'^
,这表示字符串的开头:
w <- gsub("^RT\\s", "", v)
答案 1 :(得分:0)
<- str_replace(v,"^RT","")