I tried to get a summary stat of a variable Change_1
.
I can get what I want by using codes by( df3.1_P2.1$Change_1, df3.1_P2.1$AGEGROUP_CLA, summary )
.
The output is looks like following:
I would like to somehow to get those info into a table which I can export to an excel file. what should I do? Maybe by()
is not the best way to do it. Any suggestion?
CodePudding user response:
You can rbind
the output from by
to get a dataframe which can be exported to excel.
res <- data.frame(do.call(rbind, by(mtcars$mpg, mtcars$cyl, summary)))
res
# Min. X1st.Qu. Median Mean X3rd.Qu. Max.
#4 21.4 22.80 26.0 26.66364 30.40 33.9
#6 17.8 18.65 19.7 19.74286 21.00 21.4
#8 10.4 14.40 15.2 15.10000 16.25 19.2
writexl::write_xlsx(res, 'data.xlsx')