Generate a multivariable output table for use in Excel from R

Hello everyone :slight_smile:

I have a data frame that looks like this:

county incgrp hhsize hhworker na.rm n

1 Hardin_Orange $0 - $25,170 1 0 TRUE 5205
2 Hardin_Orange $0 - $25,170 1 1 TRUE 984
3 Hardin_Orange $0 - $25,170 2 0 TRUE 1254
4 Hardin_Orange $0 - $25,170 2 1 TRUE 664
5 Hardin_Orange $0 - $25,170 2 2+ TRUE 102
6 Hardin_Orange $0 - $25,170 3 0 TRUE 211

The variables for this dataframe are:

  • county = counties
  • incgrp = income categories
  • hhsize = households with 1 person, 2 persons, 3 persons, 4 persons, 5+ persons
  • hhworker = number of workers in a household ranging from 0 to 2+ persons
  • n = weighted values needed to populate the table

I need to output this data in the following way:

Household-Income-Workers Three-Way Table

I am trying to figure out how to get the output from the data frame to the picture. So, I need the income categories on the y-axis. The logic of the x-axis is that the number of workers is stratified by the household size like in the image above. The variable "n" are the values in the cells. I can easily output this to *.csv, open it in Excel and drop it into a PivotTable, but it would be much easier to just output the file in R. Is there a way to do this? Please let me know if I can provide additional info that may help.

So two big questions to start...

  1. Do you need your data to be output into a spreadsheet format? Or is something like an html or png file acceptable? The reason I ask is because your table looks a lot like a gt table.
  2. The data in your picture does not match with the data in your reprex. Can you please post a sample of the data that you want in a reproducible form? dput(mydata) provides sufficient output.

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.