I was wondering why my pivot_longer()
call below returns nested output under the value
column?
foo <- function(){
n_subj = 5
n_trials = 20
subj_intercepts = rnorm(n_subj, 0, 1)
slope = .6
mx = 30
data = data.frame(subject = rep(1:n_subj, each=n_trials),
intercept = rep(subj_intercepts, each=n_trials)) %>%
mutate(x = rnorm(n(), mx, 1),
y = intercept + slope*(x-mean(x)) + rnorm(n(), 0, 1))
mlm = coef(summary(lmer(y ~ x + (1|subject), data=data)))[2,1]
ols = coef(summary(lm(y ~ x, data=data)))[2,1]
list(ols=ols, mlm=mlm)
}
kk <- data.frame(t(replicate(2, foo())))
pivot_longer(kk, everything())
# name value
# <chr> <list>
#1 ols <dbl [1]>
#2 mlm <dbl [1]>
#3 ols <dbl [1]>
#4 mlm <dbl [1]>