Cumulative Frequency and Probability Table in R (Examples) | Count & Sum | table & cumsum Functions

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

x <- sample(LETTERS[1:4], 100, TRUE)
head(x) # First six values of example data

table_x <- table(x) # Create frequency table
table_x # Print frequency table

cumsum_table_x <- cumsum(table_x) # Create cumulative frequency table
cumsum_table_x # Print cumulative frequency table

rownames(data_freq) <- LETTERS[1:4]
data_freq # Print data frame with relevant values

Follow me on Social Media:
Рекомендации по теме
Комментарии
Автор

Youre getting me through grad school, thanks so much! Simple straight to the point and mutiple alternatives I genuniely appreciate your help

Mcha
Автор

Joachim,
Nice presentation. There is of course prop.table. You simply wrap your table in it:
freq = You could also define each of the column separately and then cbind at the end.
freq <- as.numeric(letter_tbl)
prob_freq <- as.numeric(prop.table(freq))

cum_freq <- as.numeric(letter_cs_tbl)
prob_cum_freq <-

data_df <- data.frame(cbind(freq, prob_freq, cum_freq, prob_cum_freq))

It is perhaps the long way to get to the same result and it is all a matter of taste. I would have preferred the "tidy" way but not sure that table or prop.table work inside the tidyverse (dplyr etc).

Thanks!

haraldurkarlsson
visit shbcf.ru