how to use group by in a function in R

0 votes
2

1
The following is my code for the function I want to utilise group by in. 1, 2, and 3 all work well, however function 4 doesn't. I need help because I don't know how to solve this issue.

Number 1: create variables and a dataframe

df - data.frame(y, x) #2 group by y x - rnorm(100) y - rep(c("A", "B"), 50

group by(y) percent > percent df percent > percent
summarising with (n = n(), mean = mean(x), sd = sd(x))
# 3 make a function

function for a group (df, var1, var2)

group by(var1) percent > percent df percent > percent
summarising with (n = n(), mean = mean(var2), sd = sd(var2))
Test function #4

the issue is group(df = df, var1 = y, var2 = x) #

"Grounded df impl(data, unname(vars), drop) error:
Unknown column 'var1'
Called from: data, unname(vars), drop, grouped df impl ",
Jul 20, 2022 in Data Science by avinash
• 1,840 points

edited Mar 4 18 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP