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.

Thanks
Monty

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"
data(mtcars)
help(mtcars)
head(mtcars)
# Make a cross table of the frequencies of the "number of cylinders" 
# against the "number of gears"
help(table)
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

Gender:
1= male
2 = Female

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

Thanks for your help
Monty21

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)
library("readxl")
# The help page will give you examples
help("read_excel")

Then making the table should be straight-forward.'

HTH

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.