当 R 中以小写字母开头时,从数据框单元格中删除第一个单词
我想要清理 R 中包含细菌种类的分类表,并且想要删除所有以小写字母开头的单元格中的值。
我有一个来自分类学 df 的专栏:
物种 |
---|
Tuwongella immobilis |
Woesebacteria |
未知海洋 |
细菌 Ellin506 |
我想要:
物种 |
---|
Tuwongella immobilis |
Woesebacteria |
unwanted <- "^[:upper:]+[:lower:]+"
tax.clean$Species <- str_replace_all(tax.clean$Species, unwanted, "")
但它似乎不起作用,并且与所需的物种不匹配。
I want to clean up a taxonomy table with bacterial species in R
and I want to delete values from all cells that start with the small letter.
I have a column from taxonomy df:
Species |
---|
Tuwongella immobilis |
Woesebacteria |
unidentified marine |
bacterium Ellin506 |
And I want:
Species |
---|
Tuwongella immobilis |
Woesebacteria |
unwanted <- "^[:upper:]+[:lower:]+"
tax.clean$Species <- str_replace_all(tax.clean$Species, unwanted, "")
but it doesn't seem to work and does not match desired species.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您正在使用数据帧,我建议使用 dplyr::filter 来清理数据帧。
grepl()
返回逻辑值,!grepl(^[[:lower:]])
查找任何不以小写字母开头的内容 (^
表示字符串的开头)。If you are working with dataframe, I suggest using
dplyr::filter
to clean up the dataframe.grepl()
returns logical values,!grepl(^[[:lower:]])
looks for anything that does not start with a lower case letter (^
indicate the beginning of a string).我们可以做
We can do