Comments (5)
Hi, @robertogilsaura
You can use tab_rows
or tab_subgroup
:
library(expss)
BRAND <- c(1,2,3,2,3,2,1,2,3,4,3,2,1,2,3,4,3,4)
LIKES <- c(1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,1)
GENDER <- c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2)
cis <- data.frame(GENDER,BRAND,LIKES)
# with tab_rows
cis %>%
tab_cells(LIKES) %>%
tab_cols(total(), GENDER) %>%
tab_rows(BRAND) %>%
tab_stat_cases() %>%
tab_pivot()
# | | | | | #Total | GENDER | |
# | | | | | | 1 | 2 |
# | ----- | -- | ----- | ------------ | ------ | ------ | -- |
# | BRAND | 1 | LIKES | 1 | 3 | 2 | 1 |
# | | | | 2 | | | |
# | | | | #Total cases | 3 | 2 | 1 |
# | | 2 | LIKES | 1 | | | |
# | | | | 2 | 6 | 4 | 2 |
# | | | | #Total cases | 6 | 4 | 2 |
# | | 3 | LIKES | 1 | 6 | 3 | 3 |
# | | | | 2 | | | |
# | | | | #Total cases | 6 | 3 | 3 |
# | | 4 | LIKES | 1 | 1 | | 1 |
# | | | | 2 | 2 | | 2 |
# | | | | #Total cases | 3 | | 3 |
# and with tab_subgroup
for(i in sort(unique(cis$BRAND))){
cis %>%
tab_cells(LIKES) %>%
tab_cols(total(), GENDER) %>%
tab_subgroup(BRAND == i) %>%
tab_stat_cases() %>%
tab_pivot() %>%
set_caption(sprintf("BRAND == %s", i)) %>%
print()
}
# BRAND == 1
# | | | #Total | GENDER | |
# | | | | 1 | 2 |
# | ----- | ------------ | ------ | ------ | -- |
# | LIKES | 1 | 3 | 2 | 1 |
# | | #Total cases | 3 | 2 | 1 |
# BRAND == 2
# | | | #Total | GENDER | |
# | | | | 1 | 2 |
# | ----- | ------------ | ------ | ------ | -- |
# | LIKES | 2 | 6 | 4 | 2 |
# | | #Total cases | 6 | 4 | 2 |
# BRAND == 3
# | | | #Total | GENDER | |
# | | | | 1 | 2 |
# | ----- | ------------ | ------ | ------ | -- |
# | LIKES | 1 | 6 | 3 | 3 |
# | | #Total cases | 6 | 3 | 3 |
# BRAND == 4
# | | | #Total | GENDER |
# | | | | 2 |
# | ----- | ------------ | ------ | ------ |
# | LIKES | 1 | 1 | 1 |
# | | 2 | 2 | 2 |
# | | #Total cases | 3 | 3 |
from expss.
hi @gdemin
a lot of thanks.... second way was the output that I was looking for...
Great package expss!!!!
from expss.
Hi @gdemin
I'm deploying the process in rmarkdown, but I didn't get print tables in expss_output_viewer() mode.
This is my chunk
suppressMessages(library(expss, quietly=TRUE))
data <- suppressMessages(read_spss("~/_datos/92.expss/ems2018.sav"))
options(scipen=5,width=255)
j <- val_lab(data$ZONA)
for (i in sort(unique(data$ZONA)))
{
data %>%
tab_cells(P15) %>%
tab_cols(total(), SEXO) %>%
tab_subgroup(ZONA == i) %>%
tab_stat_cpct() %>%
tab_cells(na_if(P15, gt(5))) %>%
tab_stat_mean_sd_n() %>%
tab_pivot(stat_position = "inside_rows") %>%
set_caption(paste("|",attr(j,"names")[i])) %>%
print()
}
Table always are in text mode in the final html output, but I dont find the way for print in viewer mode. If I write expss_output_viewer() inside function, but output is HTML code.
Thank you in advance for your help ...
from expss.
Hmm... It seems it is rather tricky to print something with loops in the RMarkdown. Solution from here:
suppressMessages(library(expss, quietly=TRUE))
data <- suppressMessages(read_spss("~/_datos/92.expss/ems2018.sav"))
options(scipen=5,width=255)
j <- val_lab(data$ZONA)
for (i in sort(unique(data$ZONA)))
{
data %>%
tab_cells(P15) %>%
tab_cols(total(), SEXO) %>%
tab_subgroup(ZONA == i) %>%
tab_stat_cpct() %>%
tab_cells(na_if(P15, gt(5))) %>%
tab_stat_mean_sd_n() %>%
tab_pivot(stat_position = "inside_rows") %>%
set_caption(paste("|",attr(j,"names")[i])) %>%
htmlTable() %>%
print()
}
Note that you need to add results='asis'
to your chunk options.
from expss.
Hi @gdemin
Success, great !!!! runs properly... I would never have found the solution !!!
Here leave code for help someone with same problem... Note that is a chunk
{r, results='asis'}
j <- val_lab(data$D)
for (i in sort(unique(data$D)))
{
output <- data %>%
tab_cells(A) %>%
tab_weight(B) %>%
tab_cols(total(), C) %>%
tab_subgroup(D== i) %>%
tab_stat_cpct() %>%
tab_cells(na_if(A, gt(5))) %>%
tab_stat_mean_sd_n() %>%
tab_pivot(stat_position = "inside_rows") %>%
set_caption(attr(j,"names")[i])
print(htmlTable(output))
}
from expss.
Related Issues (20)
- Mismatches between significance test result of R and SPSS HOT 6
- How to not include subtotals in percent calculation? HOT 4
- Redundant column when using subtotal in columns HOT 4
- Help with val_lab() and var_lab() HOT 3
- Intermittent error: "duplicated values in labels" HOT 5
- Converting etable to huxtable leaves duplicate cells empty HOT 2
- 'do_repeat' functionality HOT 1
- Random error 'set_val_lab' - duplicated values in labels: HOT 13
- Please keep do_repeat HOT 2
- Unable to install without 'knitr' - move to Depends? HOT 1
- Problem at writting labelled csv files with accents in labels HOT 10
- Question about computing percentages with different bases HOT 3
- What happened to vlookup? HOT 1
- Where deprecated in future HOT 2
- Question about net HOT 2
- Shiny and expss HOT 2
- var_lab in net HOT 2
- Multiple response in function() HOT 4
- expss--where did it go? HOT 1
- use of `base::mtfrm` entails R 4.2 or later HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expss.