If you use dplyr.
suppressMessages (library(dplyr))
df<-data.frame(
ID = 1:4, age = c (43, 62, 54, 55), sex = c (0, 1, 1, 0),
BP = c (120, 130, 132, 110), BMI = c (21, 26, 23, 19)
)
result<-df%>%group_by(sex)%>%do(model=glm(BP to age+sex+BMI, data=.))
result$sex
result$model
I also want to see the results of using summary() by group
purrr
If you use the library map
.
library(purrrr)
result $model%>%map(summary)
add
Is it possible to output to the model by group?
You may have a slightly different taste, but you can name each one with names()
.
names(result$model)=c("men", "woman")
result $model $men
result $model $woman
© 2024 OneMinuteCode. All rights reserved.