r - gsub : Removing a special character at the end of a string in R

标签 r

我希望在 R 中替换字符串末尾的所有 *。

txt <- c("arm","foot-ha-*","lefroo", "bafoobar*")
gsub("/\\*$/","",txt, perl=TRUE); 

我想将txt转换为 “arm”“foo-ha-”“lefroo”“bafoobar”

我做错了什么?

谢谢!

最佳答案

您不需要正则表达式中的 /

gsub("\\*$", "", txt)

关于r - gsub : Removing a special character at the end of a string in R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16994256/

相关文章:

r - 在facet_wrap图中添加 "floating"轴标签

r - 如何使用 ggplot 以及 method = glmmTMB::glmmTMB 和点权重来可视化交互效果

r - 如何在 R 中用数字向量表示多项式

r - 如何使用 xlim 或 ylim 停止 ggrepel 重叠点

r - 在 R 中放大集群/热图

r - 带有 R 解释器和子模块的 nix-shell

r - 每行删除重复项的整洁方法

r - 什么是 R 中值 [[3L]](cond) 的误差?

R data.table 连接不等式条件

r - 图片作为 Shiny 仪表板的背景