Giter Club home page Giter Club logo

table's Introduction

Table

R package for Table1

Required library:

1. devtools - for installing Table 2. survival - sample dataset mgus 3. dplyr - piping

Optional library:

1. haven - read sav 2. data.table - fast read spss

Step 1 - Install Tablr package :

install.packages("devtools")
install.packages("survival")
library(devtools)
library(survival)
library(dplyr)
install_github("huiwk/Table")
library(Table)
set.seed(63467)

Step 2 - Preparation :

#Modify dataset, create random missing entries
dat<-survival::mgus[,c("age","sex","alb","creat","hgb")]
N<-80
inds <- as.matrix(expand.grid(1:nrow(dat), 1:ncol(dat)))
inds <- matrix(inds[!is.na(dat[inds])], ncol=2)
selected <- inds[sample(nrow(inds), N), ]
dat[selected] <- NA

#Create Par dataset [Mean(Sd)	Median[IQR]	Count(Pct)	Missing(Pct)	Order	Parameter.name.to.display	Parameters]
par<-data.frame(
  Mean.Sd.=c(1,0,1,1,1)%>%as.logical,
  Median.IQR.=c(1,0,1,1,1)%>%as.logical,
  Count.Pct.=c(0,1,0,0,0)%>%as.logical,
  Missing.Pct.=c(1,1,1,1,1)%>%as.logical,
  Order=c(4,2,3,1,5)%>%as.integer,
  Parameter.name.to.display=c("Age","Sex","Alb","Cr","Hgb"),
  Parameters=dat%>%names
)
All_group<-TRUE
By_group<-TRUE
dat<-data.frame(dat,Study_Design=sample(0:2,dim(dat)[1],replace=TRUE))%>%tibble #Create grouping variable
group_var<-"Study_Design"

Step 3 - Function Test :

1. data.split.r

data.split(dat,par$Parameters,All_group,By_group,group_var,TRUE)->d

2. get.stat.par.r

get.stat.par(par,par$Parameters)->p

3. mean_sd.r

mean_sd(d,as.vector(p[["Mean.Sd."]]),2,"(",")")
mean_sd(d,as.vector(p[["Mean.Sd."]]),3,"±","")

4. median_iqr.r

median_iqr(d,as.vector(p[["Median.IQR."]]),2,"[",",","]")
median_iqr(d,as.vector(p[["Median.IQR."]]),3,"[",",","]")

5. count_pct.r

count_pct(d,as.vector(p[["Count.Pct."]]),2,"(","%)")

6. missing_pct.r

missing_pct(d,as.vector(p[["Missing.Pct."]]),2,",","%")

7. Table1.r

Table1(dat,par,All_group,By_group,group_var,
       par$Parameters,
       mean.sd.dp = 2, mean.sd.p1 = "±", mean.sd.p2 = "",
       median.iqr.dp = 2, median.iqr.p1 = "[", median.iqr.p2 = ",", median.iqr.p3 = "]",
       count.pct.dp = 2, count.pct.p1 = "(", count.pct.p2 = ")",
       missing.pct.dp = 2, missing.pct.p1 = ",", missing.pct.p2 = "%")

table's People

Contributors

huiwk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.