Creating a cross table in R language

Dear users,

I have a dataset in Excel, I have imported in R and I want to make a cross-tabulation output.

Any suggestion what packages to use? I have tried the sjPlot and tab_xtab:

The script below it aggregated the data separately and I want them both in 1 table merged

############################ Tabulation ########################################
############################ Importing an Excel file ###########################

library(readxl)

data - read_excel("C:/Users/hasimif/Desktop/R Language/Input/data.xlsx")

View(data)

###################### CROSSTAB TABULATION PACKAGE #############################
install.packages("sjPlot")

req <- substitute(require(x, character.only = TRUE))
libs<-c("sjPlot")
sapply(libs, function(x) eval(req) || {install.packages(x); eval(req)})

################################################################################

################################ Agregations ###################################

sjPlot::tab_xtab(var.row = data$P_03, var.col = data$P_02, title = "Disaggregated data of the amount of export in 2022 by nr of employees",
var.labels = c("Amount of export in 2022", "Number of employees"),
digits = 2, show.row.prc = TRUE)

sjPlot::tab_xtab(var.row = data$P_03, var.col = data$P_04, title = "Disaggregated data of the amount of export in 2022 by share of export in sales revenue",
var.labels = c("Amount of export in 2022", "Share of export in sales revenue"),
digits = 2, show.row.prc = TRUE)

I would really encourage you to review the following guide, FAQ: Tips for writing R-related questions.
For example, the guide emphasizes asking coding questions with formatted code-chunks and a reprex.

You may have noticed folks here requesting minimal reprexes, that's because asking questions this way saves answerers a lot of time.

Reproducible Examples:

  • help make your question clear and replicable
  • increases the probability folks will reach out and try to help,
  • reduces the number of back-and-forths required to understand the question,
  • and makes your question and suggested solutions more useful to folks in the future researching similar problems.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.