示例数据:
df1 = data.frame(x1 = rep(c("foo", "bar"), 4),
x2 = rep(c("FOO", "fix", "broke", "fix"), 2))
Run Code Online (Sandbox Code Playgroud)
例如,我想更改多个不同的字符串,在本例中更改foo为done和。我正在使用和。是否可以在 后面放置多个函数,以便在同一行代码中的所有列上运行多个函数,而不是像上面重复和的示例那样:baropenstringrdplyr~acrosseverything
> df1%>%
+ mutate(across(everything(), ~ str_replace(.,"(?i)bar", "open")),
+ across(everything(), ~ str_replace(., "(?i)foo", "done")))
x1 x2
1 done done
2 open fix
3 done broke
4 open fix
5 done done
6 open fix
7 done broke
8 open fix
Run Code Online (Sandbox Code Playgroud) 我想在 .txt 文件中添加脚注flextable。理想情况下,我不想添加 aref_symbol但不确定这是否可能,但即使当我尝试在标题的第一个单元格中添加 a 时ref_symbol,我也会收到错误:
df = structure(list(Centre_group = c("NA or other", "NA or other",
"North", "North", "South east", "South east", "South west"),
reliable_use_info = c(FALSE, TRUE, FALSE, TRUE, FALSE, TRUE,
TRUE), n = c(126L, 135L, 140L, 364L, 1065L, 508L, 1126L)), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -7L), groups = structure(list(
Centre_group = c("NA or other", "North", "South east", "South west"
), .rows = structure(list(1:2, 3:4, 5:6, 7L), ptype = …Run Code Online (Sandbox Code Playgroud) 我想用来gsub从文件名中删除字符。
在下面的示例中,所需的输出是 23
digs = "filepath/23-00.xlsx"
Run Code Online (Sandbox Code Playgroud)
我可以删除 23 之前的所有内容,如下所示:
gsub("^\\D+", "",digs)
[1] "23-00.xlsx"
Run Code Online (Sandbox Code Playgroud)
或之后的所有内容:
gsub("\\-\\d+\\.xlsx$","", digs)
[1] "filepath/23"
Run Code Online (Sandbox Code Playgroud)
我如何同时做这两件事?