【发布时间】:2020-11-10 21:05:32
【问题描述】:
我有一个数据框:
ID value
1 he following object is masked from ‘package:purrr’
2 Attaching package: ‘magrittr’
3 package ‘ggplot2’ was built under R version 3.6.2
4 Warning messages:
这是一个转换列值的代码:
df <- df %>%
mutate(value = stringr::str_replace(value, '(^he following object)', '\\1'),
value = stringr::str_replace(value, '(^Attaching package:)', '\\1'),
value = stringr::str_replace(value, '(^package ‘ggplot2’)', '\\1'))
) %>%
group_by(ID, value)
输出是:
ID value
1 he following object
2 Attaching package:
3 package ‘ggplot2’
4 Warning messages:
如您所见,我在一列中多次使用 stringr::str_replace。我的实际数据要大得多(如数百万行)。这只是一个子集示例。那么,我怎样才能将这三次结合使用这个功能一次呢?我想使用相同的函数和库(没有根本的变化)
【问题讨论】: