r - 将多个函数应用于 R 中的数据框
问题描述
我正在尝试将多个函数应用于 R 中的数据框列,如下所示:
lapply(targets$phenotype, function(x) {tolower(x); gsub(" ", "_",x) })
但是,只有第二个最终运行。如果我切换 tolower 和 gsub 的顺序(只有第二个运行),也会发生同样的事情
解决方案
未tolower
更新为x
lapply(targets$phenotype, function(x) {x <- tolower(x); gsub(" ", "_",x) })
gsub
在这里,如果它是单列并且tolower
被矢量化,我们甚至不需要循环
targets$phenotype <- gsub(" ", "_", tolower(targets$phenotype))
推荐阅读
- reactjs - Redux-Observable - Cancel next request if it has same parameters with current one, but let it run when they are different
- excel - VBA: moving values over to another sheet based off of Vlookup results
- python - 彩虹色功能
- applescript - 如何使用 AppleScript 在 Safari 中打开新链接?
- r - r - arrange values in column based on unique values in another column within a group
- ruby-on-rails - 如何避免对 has_many 的 N+1 查询:通过关联
- spinnaker - Spinnaker 未显示自动触发的执行
- javascript - 如何在 html 和 javascript 中同时切换文本和颜色?
- ios - 如何在从分段控制器和文本字段中获取功能时运行
- java - 顶级 build.gradle 已损坏