(Using iris for reproducibility)
I believe wording of my questions can be improved but its a really simple problem, I need to return n_distinct
i.e. 3 if column_name=="Species"
and mean if others. The other part works good but I receive NA as output in Species column, any help what I am doing wrong.
library(tidyverse)
new_mean <- function(col_name) {
if(col_name=="Species")
{
return(n_distinct(col_name))
}
else
{
return(mean(col_name))
}
}
purrr::map_dfr(iris,new_mean)