Creating Cross table

I am new at learning R. I’m trying to create a cross table and frequency with employee data. Is there a specific syntax and package I should use to to create this table in R? Any help would be greatly appreciated.


Hi @Monty21,
Welcome to the RStudio Community Forum.
Making frequency tables in R is pretty easy (as you'd expect), as this simple example shows:

# Let's use the built-in dataset called "mtcars"
# Make a cross table of the frequencies of the "number of cylinders" 
# against the "number of gears"
table(mtcars$cyl, mtcars$gear)

We don't have your data, but hope this gets you started.

DavoWW, thank you so much. This is awesome. I heard how friendly the R community can be.

Thank you much for responding. How do I share may excel data. As I mentioned I am extremely new ( 3 days) with using R. I am looking to create a table that displays Grade by Gender. I assume I need to create a vector first? Do I need to fist upload a specific package?

I am essentially to create the below crosstable displaying the below table.

Grade by Gender

1= male
2 = Female

1 = manager,
2 = senior manager
3= Director
4=Senior Director
5= Partner
6= Senior Partner

Thanks for your help

HI @Monty21,
I suggest you read-in your Excel data using the readxl package. You need to create a data.frame (or a tibble) consisting of multiple columns of your data, all columns the same length.

install.packages("readxl", dependencies=TRUE)
# The help page will give you examples

Then making the table should be straight-forward.'


Your response is exactly what needed. Thanks again. Until the the next question :slight_smile:

Have great rest of the week

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.