r - 为什么 stringr 和 forcats 中替换的命名约定不同?
问题描述
我很难记住将键值对传递给stringr::str_replace_all()
and的正确命名约定forcats::fct_recode()
。显然,这两个函数在是否需要命名字符串向量或单个命名字符串以及对的顺序方面有所不同:
library("tidyverse")
ggplot2::diamonds %>%
mutate(cut = stringr::str_replace_all(cut,
c("Ideal" = "Awesome","
Premium" = "Deluxe")))
ggplot2::diamonds %>%
mutate(cut = forcats::fct_recode(cut,
"Awesome" = "Ideal",
"Deluxe" = "Premium"))
知道这两个函数做不同的事情,命名约定不同是有原因的吗?也许约定只是任意的——如果不是,我想了解底层逻辑。
解决方案
推荐阅读
- h2 - H2 - 在 ALTER 表之后找不到表 - 剩余的“_COPY_”表
- .net - 如果 FileSystemWatcher 在一段时间后没有触发,有没有办法抛出异常
- excel - 列中子字符串的最大值
- swift - 带有独立 WatchOS 应用程序的 Siri 表盘上的快捷方式/操作
- firebase - 将 Firebase 项目从自定义身份验证迁移到本地
- machine-learning - K-NN:训练 MSE,K=1 不等于 0
- python-3.x - 如何连接二进制图像轮廓中的点
- amazon-web-services - 在 lambda 函数中使用 EventBridge 事件模式字符串
- javascript - JavaScript 中 let 和 const 的变量声明在块作用域和全局作用域中的工作方式不同吗?
- azure - 如何在 Micorsoft Azure / Microsoft Synapse 无服务器 SQL 池服务中实现外部表的行级安全功能?