私のR関数の1つでifelse文を連鎖しようとしていました。基本的に私は何をしたいです:dplyrでifelse文を連鎖する方法
do.something <- function (df, cond=TRUE){
df %>% ifelse(cond, do something, do something else)
}
例として使用mtcarsデータセット:
select.vars <- function (df, cond=TRUE){
df %>% ifelse(cond, select(., mpg,wt), select(., hp, wt))
}
select.vars(mtcars)
エラーメッセージ:
Error in ifelse(., cond, select(., mpg, wt), select(., hp, wt)) : unused argument (select(., hp, wt))
私はちょうど私が間違っていたのだろうか。誰でも助けることができますか?どうもありがとう。
可能な重複([R条件評価パイプ演算子%>%使用] https://stackoverflow.com/questions/30604107/r-conditional-evaluation-when-using-the- pipe-operator) – HubertL
ええ、purrr ::(HubertLのリンクで)慣用的な方法だと思います。それは私が同様の質問をしたときに私が指摘していたものです。https://github.com/tidyverse/magrittr/issues/91 – Frank