r/rstats•
artgotframed

Is there a way I can make a stacked contingency table or transform "sjTable"/"sjtstackfrq" to a dataframe?

Hi everybody, sorry for the confusing question, I'm missing the terminology for what I am trying to do.

Basically, I have multiple sets of data from interviews, conducted over a series of time. Each dataset (imported to R as dataframes) has the same variables, and each variable has all the answers (coded in integers) that were given by all the respondents.

Now I basically want to generate a simple contingency table for every single variable, that contains basically all the answers of every single dataframes stacked over/under each other (see the image below, because I'm bad at describing it) and then export it to excel. Originally I wanted to use the table()-function, but not all the possible answers for a single variable were given in all the dataframes and so it wasn't possible to combine the tables, since they have different lengths.

My current workflow is that I pack loop over a list of variable, that then exports this variable from each dataframe, binds them together to a new dataframe, and then I use tab_stackfrq() from the sjPlot-package to generate this table you can see below. The table is basically exactly what I want, but since this is an HTML-table, I can't export it to something like Excel and as.data.frame() as well as readHTMLTable() just put out error-messages, that they can't deal with "sjTable"-objects/-classes.

Do any of you have any ideas how I could tackle the problem (either by transforming the "sjTable"-object or by using a completely different method to generate the tables I need)?

This HTML-Table (generated through the tab_stackfrq()-function basically shows exactly what I want, but I can't find a way to export it

Posted Jan 4, 2023, 6:12 PM UTC

82
Loading comments…