Às 17:43 de 25/03/2025, varin sacha via R-help escreveu:
Dear R-experts,

Here below a toy example not working. After some researches on the Net, still 
don't get it !

Many thanks for your precious help.


#############################
library(knitr)
library(ggplot2)
library(pollster)
library(dplyr)
statut=c("married","not married","not married","married","divorced","divorced","married","not married","divorced","not married") sex=c("male","female","female","male","female","female","male","female","male","male") color=c("red","blue","green","green","blue","red","blue","green","red","blue")
data<- data.frame(statut, sex,color)
crosstab_3way(df=data,x=statut, y= sex,z= color)
kable(digits=0,caption="Tableau 3 variables", format="html")
####################################
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Hello,

You need a weight variable to crosstab_3way.
Since there is none in the data, I have created a

weight = rep(1, length(color))



library(knitr)
library(ggplot2)
library(pollster)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#>     filter, lag
#> The following objects are masked from 'package:base':
#>
#>     intersect, setdiff, setequal, union

statut <- c("married","not married","not married","married","divorced","divorced","married","not married","divorced","not married") sex <- c("male","female","female","male","female","female","male","female","male","male") color <- c("red","blue","green","green","blue","red","blue","green","red","blue")

data <- data.frame(statut, sex, color, weight = rep(1, length(color)))

crosstab_3way(df = data, x = statut, y = sex, z = color, weight = weight)
#> # A tibble: 7 × 5
#>   statut      color female  male     n
#>   <fct>       <fct>  <dbl> <dbl> <dbl>
#> 1 divorced    blue     100     0     1
#> 2 divorced    red       50    50     2
#> 3 married     blue       0   100     1
#> 4 married     green      0   100     1
#> 5 married     red        0   100     1
#> 6 not married blue      50    50     2
#> 7 not married green    100     0     2


You can now pipe to kable. WHich was also missing an argument, x, what to plot(!)


crosstab_3way(df = data, x = statut, y = sex, z = color, weight = weight) %>%
  kable(digits = 0, caption = "Tableau 3 variables", format = "html") %>%
  writeLines(con = "./Temp/varin_sacha_2025_03_25.html")

# unlink("./Temp/varin_sacha_2025_03_25.html")



Hope this helps,

Rui Barradas


--
Este e-mail foi analisado pelo software antivírus AVG para verificar a presença 
de vírus.
www.avg.com

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to