new function

This commit is contained in:
agdamsbo 2021-04-15 08:40:34 +02:00
parent 90819eecaa
commit c029a09d07
6 changed files with 69 additions and 4 deletions

View File

@ -1,6 +1,6 @@
Package: daDoctoR
Title: Functions For Health Research
Version: 0.21.2
Version: 0.21.3
Year: 2021
Author: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>
Maintainer: Andreas Gammelgaard Damsbo <agdamsbo@pm.me>

View File

@ -20,6 +20,7 @@ export(plot_biv_olr)
export(plot_ord_odds)
export(print_reg_diff_bin)
export(quantile_cut)
export(redcap_clean_csv)
export(rep_biv)
export(rep_epi_tests)
export(rep_glm)

View File

@ -3,6 +3,7 @@
#' Using base/stats functions cut() and quantile().
#' @param x Variable to cut.
#' @param groups Number of groups.
#' @param y alternative vector to draw quantile cuts from. Limits has to be within x. Default is NULL.
#' @param na.rm Remove NA's. Default is TRUE.
#' @param group.names Names of groups to split to. Default is NULL, giving intervals as names.
#' @param ordered.f Set resulting vector as ordered. Default is FALSE.
@ -12,6 +13,16 @@
#' aa <- as.numeric(sample(1:1000,2000,replace = TRUE))
#' summary(quantile_cut(aa,groups=4)) ## Cuts quartiles
quantile_cut<-function(x,groups,na.rm=TRUE,group.names=NULL,ordered.f=FALSE){
cut(x, quantile(x,probs = seq(0, 1, 1/groups), na.rm = na.rm,names = TRUE, type = 7),include.lowest = TRUE,labels = group.names,ordered_result = ordered.f)
quantile_cut<-function (x, groups,y=NULL, na.rm = TRUE, group.names = NULL, ordered.f = FALSE)
{
if (!is.null(y)){
q<-quantile(y, probs = seq(0, 1, 1/groups), na.rm = na.rm, names = TRUE, type = 7)
}
if (is.null(y)){
q<-quantile(x, probs = seq(0, 1, 1/groups), na.rm = na.rm, names = TRUE, type = 7)
}
d<-cut(x, q, include.lowest = TRUE, labels = group.names,
ordered_result = ordered.f)
return(list(d,q))
}

23
R/redcap_clean_csv.R Normal file
View File

@ -0,0 +1,23 @@
#' Easily format csv-files for instrument opload to REDCap
#'
#' Both Numbers and Excel lacks detailed formatting options for csv-export.
#' This function formats csv-files for ReDCap instruments after export from said programs.
#' @param folder Path to desired folder.
#' @param name Desired file name.
#' @keywords redcap
#' @export
#' @examples
#' csv_redcap_cleaner("/Users/user/REDCap_conversion")
redcap_clean_csv<-function(folder,name="instrument"){
f<-folder
fn<-name
pt<-paste0(name,".csv")
p<-list.files(f, pattern=pt, full.names=TRUE)
d<-read.csv(p, header=FALSE, sep=";")
nc<-unlist(strsplit(p, "[.]"))
n<-paste0(f,"/done/",fn,".csv")
colnames(d)<-NULL
write.csv(d,n,na="",row.names = FALSE)
}

View File

@ -4,13 +4,22 @@
\alias{quantile_cut}
\title{Easy function for splitting numeric variable in quantiles}
\usage{
quantile_cut(x, groups, na.rm = TRUE, group.names = NULL, ordered.f = FALSE)
quantile_cut(
x,
groups,
y = NULL,
na.rm = TRUE,
group.names = NULL,
ordered.f = FALSE
)
}
\arguments{
\item{x}{Variable to cut.}
\item{groups}{Number of groups.}
\item{y}{alternative vector to draw quantile cuts from. Limits has to be within x. Default is NULL.}
\item{na.rm}{Remove NA's. Default is TRUE.}
\item{group.names}{Names of groups to split to. Default is NULL, giving intervals as names.}

21
man/redcap_clean_csv.Rd Normal file
View File

@ -0,0 +1,21 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/redcap_clean_csv.R
\name{redcap_clean_csv}
\alias{redcap_clean_csv}
\title{Easily format csv-files for instrument opload to REDCap}
\usage{
redcap_clean_csv(folder, name = "instrument")
}
\arguments{
\item{folder}{Path to desired folder.}
\item{name}{Desired file name.}
}
\description{
Both Numbers and Excel lacks detailed formatting options for csv-export.
This function formats csv-files for ReDCap instruments after export from said programs.
}
\examples{
csv_redcap_cleaner("/Users/user/REDCap_conversion")
}
\keyword{redcap}