Hi there: Can anyone offer a layperson's explanation for why these two ways of trying to calculate an row average of scores work differently? Thanks.
library(tidyverse)
var1<-rnorm(100)
var2<-rnorm(100)
var3<-rnorm(100)
df<-data.frame(var1, var2, var3)
#ADD IN A MISSING VALUE
df[1,1]<-NA
#I thought this would work
df %>%
select(starts_with('var')) %>%
rowwise() %>%
mutate(avg=mean(., na.rm=T))
#This does work but I don't understand why
df %>%
rowwise() %>%
mutate(avg=
mean(
c_across(starts_with('var')), na.rm=T)
)