I have a function where one of its parameters is a character variable called var. var is a dynamic character variable that takes on different combination of elements at different times. To give a little background, I have a list called comb_list that stores different combinations of elements and var eventually absorbs those elements. As an example:
input = c("a", "b") ## elements
comb_list = do.call(c, lapply(seq_along(a), combn, x = variables_of_interest, simplify = FALSE)) ## making all combinations from a and b, and storing them in comb_list.
Results:
comb_list [[1]] [1] "a"
[[2]] [1] "b"
[[3]] [1] "a""b"
class(comb_list) ## class of comb_list [1] "list"
class(comb_list[[1]]) ## class of its elements [1] "character"
Then I run a loop such that var takes on the values of comb_list. So first var = "a", then "b" and then "a","b". In my function, I would like to do a calculation only when, let's say, "b" occurs in var.
Here's what I do using dplyr:
if_else ("b" %in% var, X, Y)
But it gives me error"condition
must be a logical vector, not a grouped_df/tbl_df/tbl/data.frame
object.
I am not sure what's going wrong. Any help would be much appreciated.
Thanks!