Hi, I'm new in this community
and I have one question
Using albalon.csv in Kaggle
abalone %>%
group_by(Sex) %>%
lm(Diameter~Whole.weight, data=abalone)
you know what I mean?
I would like to derive the effect of diameter on total_weight by gender through linear regression analysis.
Male or Female
Try one of these:
library(dplyr)
iris %>%
group_by(Sex) %>%
group_map(~ broom::tidy(lm(Diameter ~ Whole.weight, data = .x)))
iris %>%
group_by(Sex) %>%
group_modify(~ broom::tidy(lm(Diameter ~ Whole.weight, data = .x)))
3 Likes
valeri
December 9, 2019, 6:41pm
3
Here is an example with mtcars
(pinched from http://varianceexplained.org/r/broom-intro/ )
library(dplyr)
library(broom)
mtcars %>% group_by(am) %>% do(tidy(lm(mpg ~ wt, .)))
so in your case
library(dplyr)
library(broom)
abalone %>%
group_by(Sex) %>%
do(tidy(lm(Diameter~Whole.weight, .)))
should work.
2 Likes
Thanks to your help
so I can deal with problem
thank you
I hadn't realize library(broom)
If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:
If your question has been answered, don't forget to mark the solution!
How do I mark a solution?
Find the reply you want to mark as the solution and look for the row of small gray icons at the bottom of that reply. Click the one that looks like a box with a checkmark in it:
[image]
Hovering over the mark solution button shows the label, "Select if this reply solves the problem". If you don't see the mark solution button, try clicking the three dots button ( ••• ) to expand the full set of options.
When a solution is chosen, the icon turns green and the hover label changes to: "Unselect if this reply no longer solves the problem". Success!
[solution_reply_author]
…
system
Closed
December 31, 2019, 12:11pm
8
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.