1

I'm trying to create a descriptive table by treatment group. For my analysis, I have 3 different partitions of the data (because I'm running 3 separate analyses) from a complete data set, but I only have one statistic from each subset that I am trying to describe, so I think it'd look better in one complete table. At the end, I'd like an output that can convert to latex (as I'm using bookdown).

I've been using the compareGroups package to easily create each table individually. I know that there is an rbind function that allows to create a stacked table, but it won't let me combine them because the n of each separate data frame is different (due to missingness). For instance, I'm trying to study marriage in one of my analyses, and later divorce (which is a separate analysis), and so the n's of these two data frames differ, but the definition of treatment group is the same.

Ideally, I'd have two columns, one for the treatment group and one for the control group. There would be two rows, one that has age of first marriage, and the second row which would have length of that first marriage, and then the respective ns of the cells.

library(compareGroups)
d1 <- compareGroups(treat ~ time1mar, 
                    data = nlsy.mar, 
                    simplify=TRUE,
                    na.action=na.omit) %>% createTable(., 
                                                   type=1,
                                                   show.p.overall = FALSE)

d2 <- compareGroups(treat ~ time1div, 
                    data = nlsy.div, 
                    simplify=TRUE,
                    na.action=na.omit) %>% createTable(., 
                                                   type=1,
                                                   show.p.overall = FALSE)

d.tot <- rbind(`First Age at Marriage` = d1, `Length of First Marriage` = d2)

This is the error that I get: Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 6626, 5057

Any suggestions?

Ryan
  • 77
  • 7
  • Hi, it is hard to help without having some example code and data that reproduce the problem. If you can provide that it will be much easier to help. See here for details: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/28481250#28481250 – joshpk Jul 24 '19 at 19:27

1 Answers1

0

The problem might be that you're using na.omit which delets the cases/rows with NAs from both of your datasets. Probably a different amount of cases get removed from each data set. But actually different numbers of row should only be a problem with cbind. However you might try to change the na.action option. I'm just guessing. As said by joshpk without sample data is difficult to reproduce your problem.

Mobody
  • 46
  • 6