1

Below is the code I am using but I keep getting an error with the area "stats= "common""

(key.stat <- stby(data = nudging[,c("SCR SCEN", "Groups")], 
                  INDICES = nudging$Groups, 
                  FUN = descr, 
                  stats= "common", 
                  transpose=TRUE, 
                  style = "rmarkdown", 
                  plain.ascii = FALSE))

The error code is:

Error: Can't subset columns that don't exist. x Column common doesn't exist. Run rlang::last_error() to see where the error occurred.

The package is summarytools. The stby code does not work and the error appears at the stats= "common" line. Groups is the IV and is categorical and SCR SCEN the dependent variable and is continuous. Could it be a fault with the data or the Rstudio version?

  • Welcome to Stack Overflow. Please [make this question reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by including a small representative dataset in a plain text format and all the relevant code - what library is required for `stby`, for example? – neilfws Jan 19 '22 at 23:39

1 Answers1

1

Not sure why it's not working for you. I tried a similar operation and even made a variable with spaces in the name in the mtcars data and it worked. Does this code work for you?

library(summarytools)
data(mtcars)
mtcars <- mtcars %>% rename("miles per gallon" = mpg)
stby(data = mtcars[,c("miles per gallon", "hp", "cyl")], 
                  INDICES = mtcars$cyl, 
                  FUN = descr, 
                  stats= "common", 
                  transpose=TRUE, 
                  style = "rmarkdown", 
                  plain.ascii = FALSE)

Output

### Descriptive Statistics  
#### mtcars  
**Group:** cyl = 4  
**N:** 11  

  |               &nbsp; |  Mean | Std.Dev |   Min | Median |    Max | N.Valid | Pct.Valid |
  |---------------------:|------:|--------:|------:|-------:|-------:|--------:|----------:|
  |              **cyl** |  4.00 |    0.00 |  4.00 |   4.00 |   4.00 |   11.00 |    100.00 |
  |               **hp** | 82.64 |   20.93 | 52.00 |  91.00 | 113.00 |   11.00 |    100.00 |
  | **miles per gallon** | 26.66 |    4.51 | 21.40 |  26.00 |  33.90 |   11.00 |    100.00 |
  
**Group:** cyl = 6  
**N:** 7  

  |               &nbsp; |   Mean | Std.Dev |    Min | Median |    Max | N.Valid | Pct.Valid |
  |---------------------:|-------:|--------:|-------:|-------:|-------:|--------:|----------:|
  |              **cyl** |   6.00 |    0.00 |   6.00 |   6.00 |   6.00 |    7.00 |    100.00 |
  |               **hp** | 122.29 |   24.26 | 105.00 | 110.00 | 175.00 |    7.00 |    100.00 |
  | **miles per gallon** |  19.74 |    1.45 |  17.80 |  19.70 |  21.40 |    7.00 |    100.00 |

**Group:** cyl = 8  
**N:** 14  

  |               &nbsp; |   Mean | Std.Dev |    Min | Median |    Max | N.Valid | Pct.Valid |
  |---------------------:|-------:|--------:|-------:|-------:|-------:|--------:|----------:|
  |              **cyl** |   8.00 |    0.00 |   8.00 |   8.00 |   8.00 |   14.00 |    100.00 |
  |               **hp** | 209.21 |   50.98 | 150.00 | 192.50 | 335.00 |   14.00 |    100.00 |
  | **miles per gallon** |  15.10 |    2.56 |  10.40 |  15.20 |  19.20 |   14.00 |    100.00 |
DaveArmstrong
  • 18,377
  • 2
  • 13
  • 25
  • The code does not work and the error appears at the stats= "common" line. Groups is the IV and is categorical and SCR SCEN the dependent variable and is continuous. Could it be a fault with the data or the Rstudio version? – Tamara D. Reid Jan 20 '22 at 00:02
  • Which version of R are you using? – DaveArmstrong Jan 20 '22 at 00:43
  • I am using R-4.1.2. and Rstudio -2021.09.1-372 – Tamara D. Reid Jan 20 '22 at 10:32
  • I think @neilfws was right, for us to help you any further, you need to provide some data that we can use to reproduce the problem. – DaveArmstrong Jan 20 '22 at 12:37
  • Thanks for your help. I started a new R markdown and the problem must be in conflicting libraries. Just using summarytools package gives no error but when I add other packages to carry out other analyses it bring up an error. – Tamara D. Reid Jan 20 '22 at 15:06