0

Suppose I have a data frame df

df <- tribble( ~x, ~y, 1, 'x > 3', 5, 'x > 2', 10, 'x > 1' )

I want to create a new variable z by the condition in y, say

df %>% mutate(z = if_else(condition, 1, 0))

here the condition is in column y.

Can I create the new variable in tidy way?

Bob
  • 37
  • 6
  • As this is a combined question with duplicates as indicated by @tmfmnk I provide a solution how to get a solution as desired: `library(dplyr) library(rlang) library(purrr) df %>% rowwise() %>% mutate( z = as.numeric(map_lgl(y, ~eval_tidy(parse_expr(paste0("all(", .x, ")"))))) )` – TarJae Apr 07 '23 at 09:06

0 Answers0