r - R中的动态函数名称
问题描述
我需要做的是在循环中同时使用 R 中的which.min
和which.max
函数。
我可以只使用一个if
声明(即if find_max_value == TRUE then which.max(…) else which.min(…)
但我想知道是否有一种方法可以真正使函数名称动态化。例如:
min_or_max = 'max'
special_text = paste('which.',min_or_max,sep='')
special_text(df_results$point)
有什么办法可以使上面的文字起作用吗?
解决方案
我们可以invoke
使用purrr
library(purrr)
invoke(special_text, list(mtcars$cyl))
#[1] 5
推荐阅读
- json - 如何扩展 JSON 字符串中的 bash 变量?
- performance - 有没有办法在 nagios/icinga 性能数据中为标签添加多个值
- python - 对 neo4j 节点进行时间版本控制的最佳方法是什么?
- database - 通过 API 创建 MongoDB Atlas 数据库的副本
- reactjs - 仅在带有道具的路线上做出反应而不进行 api 调用
- sql - 为什么我违反了完整性约束?(ORA-02291)
- flutter - Flutter Bloc:为什么在通知父 BlocListener 之前使用新状态构建子 BlocBuilder?
- amazon-web-services - AWS EMR Bootstrap action "aws s3 cp ..." to download 11GB file failing due to [Errno 28] No space left on device
- html - 当我在 css 中使用 float:left 时,固定在顶部的导航栏菜单中的文本会移动一点
- javascript - 显示从 url 到 objectUrl 的 base64 图像