2
I have tried in every way to write a code that creates a relative frequency table, but I could not. I have a dataframe with the following variables:
RANGE_DIAS
: Interval of days between order date and billing.QTDE
: Invoiced amount.COD_PRODUTO
: Product code.DATA
: Billing date
The name of the dataframe is service
I created several subsets (var_temp
) with each date and each product and I put them together at the end (df_temp
) because I couldn’t figure out how to make the table with the relative frequency with the amount of products per day.
I need something that generates the final tabulation without having to create separate subsets and put them all together at the end. Something that reads each date and product and calculates the relative frequency of the day and not the overall total of the main dataframe.
I’m using the tidyverse and janitor packages.
[https://docs.google.com/spreadsheets/d/12e-SOwfRB_QlTCrd0o6S7mwyGzaS9R8oNPk79ripSgU/edit?usp=sharing]
group_by(RANGE_DIAS) %>%
filter(DATA == "2020-11-20",
COD_PRODUTO == "B41") %>%
tabyl(RANGE_DIAS) %>%
arrange(factor(RANGE_DIAS, levels = c("1 ~ 30", "31 ~ 60", "61 ~ 90",
"91 ~ 120", "121 ~ 150", "151 ~"))) %>%
adorn_pct_formatting(digits = 2, affix_sign = F)
var_temp <- var_temp %>%
mutate(COD_PRODUTO = "B41", DATA = "2020-11-20")
df_temp <- df_temp %>%
bind_rows(var_temp)
df_temp
Sensational! Thank you so much for your help! I wish your knowledge to multiply even more! Grateful! Worked perfectly, Excellent solution!
– Maximiliano Prado
Oops! I’m glad you helped, I’m happy! Big Max Hug!
– lmonferrari