0

I'm new beginner to R, trying to cross-tabulate the variables, use the ctable() function from package "summarytools".

But I'm encountering some errors that look like the following. enter image description here

I'm learning to use R by following the worksheet for categorical data analysis of R. The result should look like this. enter image description here

I will be grateful if you can help me to figure out what's going wrong.

kjetil b halvorsen
  • 1,206
  • 2
  • 18
  • 28
  • 2
    Please do not post images of code. Instead, please [edit] your question and paste the code in directly. Images can't be copied and pasted into an editor and compiled to reproduce the problem, are hard to read on mobile devices, may be blocked by proxies or firewalls, and can't be searched and therefore aren't useful to future readers. For more information, please see [this Meta post](https://meta.stackoverflow.com/questions/285551/). – Ian Campbell Dec 28 '22 at 04:01
  • 1
    In addition to Ian's comment, please provide a sample of your dataset `elsa` (using `dput(head(elsa))` for instance). Otherwise, it is very difficult to know where the problem comes from. – Dan Chaltiel Dec 28 '22 at 07:43
  • does it help to specifiy the desired number of decimal digits, like: `ctable( ... , round.digits = 1, ...)`? – I_O Dec 28 '22 at 21:19

1 Answers1

1

Per others, yes include data and code so the error is reproducible.

I just had this issue when I updated R and packages - not sure if it was a new version of summarytools or something else. Make sure the columns you will use in ctable are factor. Not sure if yours are character. I was having this problem because my columns were numeric.

Something like (using dplyr):

elsa <- elsa %>%
  mutate(
    sex = factor(sex),
    heart_attack = factor(heart_attack)
  )

ctable(elsa$sex,elsa$heart_attack)

Good luck!

shs
  • 3,683
  • 1
  • 6
  • 34
bstRack
  • 11
  • 4