Comments (4)
I think it is better to make functions with two arguments - data
and character variable name. And for selection use mrset_p
- it selects by perl-style regular expression:
library(DT)
library(dplyr)
library(expss)
library(highcharter)
data <- data.frame(
R1 = c(1, 2, 3, 4, 5, 6),
R2 = c(2, 4, 6, 8, 10, 12),
R3_1 = c(1, 1,3, 2, 1, 1),
R3_2 = c(3, 2, 1, 1, 1, 2)
)
f1 <- function(data, variable){
tab <- data %>%
tab_cols(total()) %>%
tab_cells('|'=unvr(data[[variable]])) %>%
tab_stat_cpct(total_row_position = 'none') %>%
tab_pivot()
colnames(tab) <- c('lab', 'pct')
dt <- as.datatable_widget(tab)
grf <- hchart(tab,'bar', hcaes(lab, pct))
return(list(tab, dt, grf))
}
f1m <- function(data, variable){
tab <- data %>%
tab_cols(total()) %>%
tab_cells('|'=unvr(mrset_p(variable))) %>%
tab_stat_cpct(total_row_position = 'none') %>%
tab_pivot()
colnames(tab) <- c('lab', 'pct')
dt <- as.datatable_widget(tab)
grf <- hchart(tab,'bar', hcaes(lab, pct))
return(list(tab, dt, grf))
}
listR1 <- f1(data, "R1")
listR2 <- f1(data, "R2")
listR3 <- f1m(data, "^R3_") # "^" means "starts with"
from expss.
Thanks @gdemin. It runs ok. I save your recommendation.
Another question arose in this project. I have to create a header with new variables created from a condition of the type:
df=data.frame(A4_1=c(1,2,3,1,6,2,1), A4_2=c(6,6,8,3,4,5,6))
df %>%
tab_cells(total()
,'Pregnancy1'=mrset(A4_1 %to% A4_2) %has% 6
,'Pregnancy2'=mrset(A4_1 %to% A4_2) %has% 8
) %>%
tab_stat_cases() %>%
tab_pivot()
The result for each line is TRUE/FALSE columns. Can we change label (TRUE/FALSE) of the columns in the table request? I tried using the label=
parameter of mrset()
but it had no effect on the output. I know I can edit the final etable object or create the variables initially, but in case there is a trick utility to request on the same table.
Thanks in advance.
Best regards.
from expss.
You can set value labels on the result:
library(expss)
df=data.frame(A4_1=c(1,2,3,1,6,2,1), A4_2=c(6,6,8,3,4,5,6))
df %>%
tab_cells(total()
,'Pregnancy1'=mrset(A4_1 %to% A4_2) %has% 6 %>% set_val_lab(c("A" = TRUE, "B" = FALSE))
,'Pregnancy2'=mrset(A4_1 %to% A4_2) %has% 8 %>% set_val_lab(c("C" = TRUE, "D" = FALSE))
) %>%
tab_stat_cases() %>%
tab_pivot()
from expss.
Wow, Awesome!!!
As always, I appreciate the work and quick your feedback.
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 15
- Please keep do_repeat HOT 2
- Unable to install without 'knitr' - move to Depends? HOT 1
- Custom table significance / Count of missing values in total rows HOT 5
- 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
- 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.