I am using the below function to run multiple regression models, need to understand how to export the results to a .csv file so that I can use it in my database.
Faltu %>%
group_by(subgroup) %>%
do(tidy(lm(sales ~ month_year + weekday + sequence, .)))
Where Faltu is my data frame.

We could pipe write.csv at the end of your code:
Documentation of write.csv see here: https://www.rdocumentation.org/packages/AlphaPart/versions/0.8.1/topics/write.csv
# general:
write.csv(df,'Result.csv', row.names = FALSE)
# with your code:
Faltu %>%
group_by(subgroup) %>%
do(tidy(lm(sales ~ month_year + weekday + sequence, .))) %>%
write.csv('Result.csv')
Output: file: Result.csv in your working directory:
"subgroup","term","estimate","std.error","statistic","p.value"
1,"Mens","Fixed","(Intercept)","0.849",0.302
2,"Mens","Fixed","month_year","0.0113",0.0226
3,"Mens","Fixed","weekday","0.449",0.0425
4,"Mens","Fixed","sequence","-0.000914",0.000322
5,"Mens","Pants","(Intercept)","0.474",4.63
6,"Mens","Pants","month_year","0.112",0.233
7,"Mens","Pants","weekday","0.387",0.362
8,"Mens","Pants","sequence","-0.204",0.342
9,"Mens","Pull","On","(Intercept)",0.271
10,"Mens","Pull","On","month_year",0.0514
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With