2

I am trying to bind two tables by row but unable to bind it. do we have any solution to bind it

mtcars$vs<-factor(mtcars$vs, levels=c(0,1), labels=c("Male","female"))
mtcars$am<-factor(mtcars$am, levels=c(0,1), labels=c("Male","female"))


t1 <- expss::cro_cpct(mtcars$vs) %>% t()
t2 <- expss::cro_cpct(mtcars$am) %>% t()
t3 <- rbind(t1,t2)
Error in match.names(clabs, names(xi)) : 
  names do not match previous names

output required enter image description here

user438383
  • 5,716
  • 8
  • 28
  • 43
samrr_tr
  • 81
  • 8
  • ? https://stackoverflow.com/questions/12019461/rbind-error-names-do-not-match-previous-names – QHarr May 10 '22 at 05:24

1 Answers1

0

You have different column names, that's why you can't rbind tables. You need to do something to make column names the same, for example:

library(expss)
data("mtcars")
mtcars$vs<-factor(mtcars$vs, levels=c(0,1), labels=c("Male","female"))
mtcars$am<-factor(mtcars$am, levels=c(0,1), labels=c("Male","female"))

# set the same variable labels on both variable
var_lab(mtcars$vs) = "|"
var_lab(mtcars$am) = "|"

t1 <- expss::cro_cpct(mtcars$vs) %>% t()
t2 <- expss::cro_cpct(mtcars$am) %>% t()
t3 <- rbind(t1,t2)
Gregory Demin
  • 4,596
  • 2
  • 20
  • 20