diff --git a/report.html b/report.html index 063db62..d263ed3 100644 --- a/report.html +++ b/report.html @@ -1519,13 +1519,16 @@ ordered from wish.com valid_percent <- round(p * 100, digits = rounded_digits) na_percent <- round(na_count / length(data) * 100, digits = rounded_digits) - percent <- round(frequency/total_count*100, digits = rounded_digits) + percent_raw <- frequency/total_count*100 + percent <- round(percent_raw, digits = rounded_digits) cumulative_percent <- round(cumsum(p) * 100, digits = rounded_digits) - freq_table <- cbind(frequency, percent, valid_percent, cumulative_percent) + freq_table <- cbind(frequency, percent, percent_raw, valid_percent, cumulative_percent) - valid_percent_sum <- sum(as.data.frame(freq_table)$percent) + valid_percent_sum <- round(sum(as.data.frame(freq_table)$percent_raw), digits = rounded_digits) Valid_Total <- c(valid_count, valid_percent_sum, 100, NaN) - + + freq_table <- subset(freq_table, select = -c(percent_raw)) + NAs <- c(na_count, na_percent, NaN, NaN) Total <- c(total_count, 100, NaN, NaN) print(rbind(freq_table, Valid_Total, NAs, Total)) @@ -2420,7 +2423,7 @@ age <- 2021 - birthyears ## 48 1 0.94 0.94 98.11 ## 49 1 0.94 0.94 99.06 ## 50 1 0.94 0.94 100.00 -## Valid_Total 106 99.98 100.00 NaN +## Valid_Total 106 100.00 100.00 NaN ## NAs 0 0.00 NaN NaN ## Total 106 100.00 NaN NaN
# with NA
@@ -2449,7 +2452,7 @@ freq(2021 - litdata$D7)
## 48 1 0.32 0.94 98.11 ## 49 1 0.32 0.94 99.06 ## 50 1 0.32 0.94 100.00 -## Valid_Total 106 33.89 100.00 NaN +## Valid_Total 106 33.87 100.00 NaN ## NAs 207 66.13 NaN NaN ## Total 313 100.00 NaN NaN diff --git a/report.rmd b/report.rmd index 00d1c7e..c5dbec9 100644 --- a/report.rmd +++ b/report.rmd @@ -45,13 +45,16 @@ freq <- function(data, rounded_digits = 2) { valid_percent <- round(p * 100, digits = rounded_digits) na_percent <- round(na_count / length(data) * 100, digits = rounded_digits) - percent <- round(frequency/total_count*100, digits = rounded_digits) + percent_raw <- frequency/total_count*100 + percent <- round(percent_raw, digits = rounded_digits) cumulative_percent <- round(cumsum(p) * 100, digits = rounded_digits) - freq_table <- cbind(frequency, percent, valid_percent, cumulative_percent) + freq_table <- cbind(frequency, percent, percent_raw, valid_percent, cumulative_percent) - valid_percent_sum <- sum(as.data.frame(freq_table)$percent) + valid_percent_sum <- round(sum(as.data.frame(freq_table)$percent_raw), digits = rounded_digits) Valid_Total <- c(valid_count, valid_percent_sum, 100, NaN) - + + freq_table <- subset(freq_table, select = -c(percent_raw)) + NAs <- c(na_count, na_percent, NaN, NaN) Total <- c(total_count, 100, NaN, NaN) print(rbind(freq_table, Valid_Total, NAs, Total))