Skip to content
Prev 389240 / 398506 Next

[R Code] Split long names in format.ftable

Dear List members,


I have uploaded an improved version on Github. The function is now fully 
functional:
- justify: left, right, cent...: TODO centre vs center;
- sep: separator when printing;
- pos: Top, Bottom; TODO: Middle;

see:
https://github.com/discoleo/R/blob/master/Stat/Tools.Data.

I will address some open questions in a separate post.


### Test
# Required:
# - all functions from Github / section "Formatting":
#?? from space.builder() to ftable2();


### Data
mtcars$carbCtg = cut(mtcars$carb, c(1, 2, 4, 8), right=FALSE)
tbl = with(mtcars, table(cyl, hp, carbCtg, gear))
id = c(1,3,4);
xnm = c("Long\nname: ", "", "Extremely\nlong\nname: ")
xnm = paste0(xnm, names(dimnames(tbl))[id]);
names(dimnames(tbl))[id] = xnm;
ftbl = ftable(tbl, row.vars = id);

### FTABLE
ftable2(ftbl, sep="|"); # works nicely
ftable2(ftbl, sep=" ")
ftable2(ftbl, sep=" | ")
ftable2(ftbl, sep=" | ", justify="left")
ftable2(ftbl, sep=" | ", justify="cent") # TODO: center vs centre
ftable2(ftbl, sep=" | ", justify="left", justify.lvl="c")


Sincerely,


Leonard
On 9/15/2021 11:14 PM, Leonard Mada wrote: