A bit improved
This commit is contained in:
		
							parent
							
								
									3ae01d771f
								
							
						
					
					
						commit
						1871414592
					
				
							
								
								
									
										149
									
								
								report.html
									
									
									
									
									
								
							
							
						
						
									
										149
									
								
								report.html
									
									
									
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										29
									
								
								report.rmd
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								report.rmd
									
									
									
									
									
								
							@ -34,26 +34,27 @@ if (!require(moments)) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
## Frequency Table ordered from wish.com
 | 
					## Frequency Table ordered from wish.com
 | 
				
			||||||
```{r}
 | 
					```{r}
 | 
				
			||||||
freq <- function(data) {
 | 
					freq <- function(data, rounded_digits = 2) {
 | 
				
			||||||
 | 
					  # counts
 | 
				
			||||||
 | 
					  total_count <- length(data)
 | 
				
			||||||
  na_count <- length(data[is.na(data)])
 | 
					  na_count <- length(data[is.na(data)])
 | 
				
			||||||
  valid_count <- length(data) - na_count
 | 
					  valid_count <- total_count - na_count
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  frequency <- table(data)
 | 
					  frequency <- table(data)
 | 
				
			||||||
  p <- prop.table(frequency)
 | 
					  p <- prop.table(frequency)
 | 
				
			||||||
  percent <- round(p * 100, digits = 2)
 | 
					  valid_percent <- round(p * 100, digits = rounded_digits)
 | 
				
			||||||
  frequency_sum <- cumsum(frequency)
 | 
					  na_percent <- round(na_count / length(data) * 100, digits = rounded_digits)
 | 
				
			||||||
  hkum <- cumsum(p)
 | 
					 | 
				
			||||||
  percent_sum <- round(hkum * 100, digits = 2)
 | 
					 | 
				
			||||||
  freq_table <- cbind(frequency, percent, frequency_sum, percent_sum)
 | 
					 | 
				
			||||||
  valid_percent <- round(valid_count / length(data) * 100, digits = 2)
 | 
					 | 
				
			||||||
  na_percent <- round(na_count / length(data) * 100, digits = 2)
 | 
					 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					  percent <- round(frequency/total_count*100, digits = rounded_digits)
 | 
				
			||||||
 | 
					  cumulative_percent <- round(cumsum(p) * 100, digits = rounded_digits)
 | 
				
			||||||
 | 
					  freq_table <- cbind(frequency, percent, valid_percent, cumulative_percent)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  print(freq_table)
 | 
					  valid_percent_sum <- sum(as.data.frame(freq_table)$percent)
 | 
				
			||||||
 | 
					  Valid_Total <- c(valid_count, valid_percent_sum, 100, NaN)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  count <- c(valid_count, na_count, valid_count + na_count)
 | 
					  NAs <- c(na_count, na_percent, NaN, NaN)
 | 
				
			||||||
  percent <- c(valid_percent, na_percent, valid_percent + na_percent)
 | 
					  Total <- c(total_count, 100, NaN, NaN)
 | 
				
			||||||
  df <- data.frame(count, percent, row.names = c("valid", "NA", "Total"))
 | 
					  print(rbind(freq_table, Valid_Total, NAs, Total))
 | 
				
			||||||
  print(df)
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
*Source:  https://tellmi.psy.lmu.de/tutorials/deskriptive-statistiken-und-grafiken.html#haeufigkeiten-diskret and adapted*
 | 
					*Source:  https://tellmi.psy.lmu.de/tutorials/deskriptive-statistiken-und-grafiken.html#haeufigkeiten-diskret and adapted*
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user