Calculate Percentage by Group in R (2 Examples) | Subgroup Probability | group_by & mutate Functions

preview_player
Показать описание
R code of this video:

subgroup = letters[1:4],
value = 1:12)

data_new1 <- transform(data, # Calculate percentage by group
perc = ave(value,
group,

library("dplyr")

data_new2 <- data %>% # Calculate percentage by group
group_by(group) %>%
mutate(perc = value / sum(value)) %>%

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

i'm not getting suggestion of perc=ave code, and not getting executed while running

Anonymouslearner
Автор

I can't see.... If it could be zoomed in

BONGANIMO
Автор

hello, I would like to know if there is one more column(subgroup), then how to calculate the percentage?Thank you!!

miniminj
Автор

Thank you. Is it possible to add a percentage symbol for each number in the new column

abbasdwain
Автор

I just completed this playlist and this is very helpful for me. Thank you

PrinceKumar-cmnw