I'm using the lme
function from the nlme
package and having a hard time trying to apply it to each column of my tibble. I can successfully run it 'manually' with a single column, but fail when trying to use purrr::map
. I feel like something is right under my nose, but I'm not seeing it. Any help would be appreciated.
library(tidyverse)
library(nlme)
# Create Tibble
df <- tibble(
id = rep(1:5, length = 30),
ko = as_factor(rep(c('ctrl', 'ko1', 'ko2', 'ko3', 'ko4', 'ko5'), each = 5)),
marker1 = rnorm(30),
marker2 = rnorm(30)
)
# 'Manual' calculation
df %>% lme(marker1 ~ ko, random = ~1|id, data = .)
# Attempt at calculating lme for each column
df %>% map_if(is_double, ~ lme(.x ~ ko, random = ~ 1|id, data = .))
# Ideal would be to get the tibble of each like:
df %>% summarize(broom.mixed::tidy(lme(marker1 ~ ko, random = ~1|id, data = .)))