
CROSSTABLES IN R | DATA VISUALIZATION A crosstable, also known as a contingency table, is a table showing the frequency of occurrences of certain events or values within different groups or categories. In R, the table() function can be used to create a crosstable. For example, if you have a categorical variable "Gender" and another categorical variable "Age group", you can create a crosstable showing the number of occurrences of each age group for each gender by running: # Create example data Gender <- sample ( c ( "Male" , "Female" ) , 100 , replace = TRUE ) Age <- sample ( 18 : 80 , 100 , replace = TRUE ) Age_Group <- cut ( Age, c ( 18 , 30 , 40 , 50 , 60 , 70 , 80 ) , labels = c ( "18-29" , "30-39" , "40-49" , "50-59" , "60-69" , "70-79" ) ) data <- data.frame ( Gender, Age_Group ) table ( data $Gender , data $Age_Group ) 18-29 30-39 40-49 50-59 60-69 70-79...