【发布时间】:2015-10-27 19:46:19
【问题描述】:
假设数据框是df,列foo。有没有办法删除R中数据框列中以@开头的字符串。
例子:
df <- data.frame(foo=c("@john is awesome than @steve",
"@steve is good","@mike is nice"))
df
foo
1 @john is awesome than @steve
2 @steve is good
3 @mike is nice
如何删除以@开头的整个名称@john、@Steve、@mike。
最终输出应该是
foo
1 is awesome than
2 is good
3 is nice
我想删除数据框df 中以分隔符@ 开头的列foo 中的所有字符串。
【问题讨论】:
-
gsub("@.*?[ ]| @.*?$","",df$foo) [1] "is awesome than" "is good" "is nice" -
within.list(df, {foo <- gsub("[ ]*\\@[^ ]+", "", foo)})