0

So I am currently trying to make a summary statistics table using Table1 in R. Here is my code thus far:

my.render.cont <- function(x) {
  with(stats.apply.rounding(stats.default(x), digits = 3), 
       c("", "Mean (SD)" = sprintf("%s (&plusmn; %s)", MEAN, SD)))
}

my.render.cat <- function(x) {
  c("", sapply(stats.default(x), function(y) 
    with(y, sprintf("%d (%0.0f %%)", FREQ, PCT))))
}

table1(~ fs_hm + finsecure + fs_vlow + zfinlit + parent_conf + 
       age + female,
       render.continuous=my.render.cont, render.categorical = my.render.cat,
       data = df)

My problem is that the variable "zfinlit" is standardized with mean 0 and unit SD. However, when table1 computes the mean the output in my table has close to ten zeroes followed by three integers rather than simply a zero. What it is doing is technically correct of course, but not how I want my table to look.

Is there a fix to this problem anyone knows of? I've read some of the documentation and other examples to no avail. Any help is greatly appreciated!

  • Round or format. – IRTFM Aug 28 '21 at 02:07
  • @IRTFM Tried that already; doesn't work – James Bradley Aug 28 '21 at 02:29
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Aug 28 '21 at 02:52
  • I wish upvoting a comment would make it appear in bold. – IRTFM Aug 28 '21 at 02:56
  • To elaborate on Mr. Flick's comment, we need a small sample of your data to be able to run your code and see the problem. Please edit your post and include a bit of data. – David J. Bosak Sep 01 '21 at 00:37

0 Answers0