r - 试图删除第一次出现的字符 |
问题描述
我正在尝试删除|
数据中的第一个。当我运行以下命令时:
yy <- y %>%
mutate_all(funs(sub("|", "", .)))
什么都没发生。
我在其他列中还有其他出现,|
所以我不想删除所有这些。我能够|
使用以下内容删除最后一次出现的mutate_all(funs(gsub("(.*)\\|(.*)", "\\1\\2", .)))
- 现在我想做同样的事情,但第一次出现。
数据:
y <- structure(list(grp = c("2902", "9738", "9143", "3990", "10488",
"9581", "10905", "9859", "8787", "8626"), HD = c("| CarrolsRestr 4Q EPS 16c Vs EPS 22c ",
"| Press Release: Fitch Affirms Aeroports de Paris SA at 'A+'; Outlook Stable ",
"| MSC Reports Fiscal 2017 First Quarter Results ", "| Goodrich Announces Third Quarter 2009 Net Income per Diluted Share of $1.14, Adjusts Outlook for Full Year 2009, Provides Outlook for 2010 ",
"| *Vera Bradley 1Q Loss/Shr 4c >VRA ", "| *Fitch Affirms One Re's IFS at 'BBB-'; Outlook Stable ",
"| Johnson Controls 2014 first quarter earnings increase 31 percent on higher revenues and improved profitability; affirms guidance for fiscal 2014 ",
"| eBay Inc. Reports Third Quarter 2017 Results ", "| S&P Rating Shift a Sober Reminder for Australia -- Market Talk ",
"| Jeff Immelt: GE 'Underowned' by Big Investors "), WC = c("| 191 words ",
"| 2,493 words ", "| 2,068 words ", "| 6,275 words ",
"| 3,912 words ", "| 1,907 words ", "| 2,452 words ",
"| 5,227 words ", "| 1,594 words ", "| 920 words ")), class = "data.frame", row.names = c(NA,
-10L))
解决方案
这对我有用:
y$HD <- sub("|", "", y$HD, fixed = TRUE)
y$WC <- sub("|", "", y$WC, fixed = TRUE)
推荐阅读
- javascript - React redux,数组状态不更新
- memory-management - 具有 CPU 和内存可视化的循环内存调度
- go - 评估期望值为 Go 接口的 hcl.Expression
- java - 注入的类是否必须具有特定于弹簧的注释?
- python - Dash 中的 Windrose (Barpolar) 未更新
- openstreetmap - 如何仅显示没有节点或方式的关系
- macos - 如何从 Intel Mac 在 Silicon Mac M1 上运行 Dockerfile
- python - 在具有多个网络和方法的模型类上使用 writer.add_graph() 时出现问题,这些网络和方法采用不同的输入
- javascript - 如何在 map() 函数中获取反应道具
- java - Spring也用于前端是否正确?