dplyr mutate not applying to individual element of field
dplyr mutate not applying to individual element of field I'm trying to do a calculation using an home made function inside a mutate call and it's not doing what I'm expecting it to do. mutate Here is a reproducible example: library(dplyr) #the data dd <- structure(list(fire_zone = c("ET", "EJB", "WJB"), base_med = c(1, 1, 2)), class = "data.frame", row.names = c(NA, -3L)) # my home made function med2lambda <- function(med) polyroot(c(-0.02, 1/3 - med, 1)) %>% suppressWarnings(as.numeric(.)) %>% max So, what my function does is to estimate the lambda associated to the median from a Poisson distribution by calculating the root of a quadratic function. Despite the long explanation, it's actually pretty basic: med2lambda(1) [1] 0.695426 med2lambda(2) [1] 1.678581 Now, I want to use it in a mutate call to add a field giving the lambda associated to each median in the table: mutate dd %>% mutate(lambda = med2lambda(...