slide: The slide function

View source: R/slideBar.R

slideR Documentation

The slide function

Description

This function transforms the input data file by shifting any given toilet technologies to another category until a goal is reached for that category.

Usage

slide(data, precision, moved, fromColumns, toColumns, context)

Arguments

data

The input dataframe (but only the urban or rural fraction, they have to be analyzed one by one)

precision

The precision of the iterations (0.001 does not take too long; 0.01 is much faster)

moved

A percentage indicating how many percentage points need to be moved (i.e., how much the slider bar button has moved)

fromColumns

The columns(s) where you want the percentages to decrease

toColumns

The column(s) where you want the percentages to increase

Examples

# Rules:
# 1a. If the red button moves to the right, then toColumn=c("openDefecation") and fromColumns=c("pitSlab","pitNoSlab","bucketLatrine","containerBased")
# 1b. If the red button moves to the left, then toColumn=c("pitSlab") and fromColumns=c("openDefecation","other","hangingToilet")
# 2a. If the orange button moves to the right, then toColumn=c("pitSlab") and fromColumns=c("compostingToilet")
# 2a. If the orange button moves to the left, then toColumn=c("compostingToilet") and fromColumns=c("pitSlab","pitNoSlab","bucketLatrine","containerBased")
# 3a. If the yellow button moves to the right, then toColumn=c("compostingToilet") and fromColumns=c("flushSeptic","flushPit","flushOpen","flushUnknown")
# 3b. If the yellow button moves to the left, then toColumn=c("flushSeptic","flushPit") and fromColumns=c("compostingToilet")
# 4a. If the green button moves to the right, then toColumn=c("flushSeptic","flushPit") and fromColumns=c("flushSewer")
# 4b. If the green button moves to the left, then toColumn=c("flushSewer") and fromColumns=c("flushSeptic","flushPit","flushOpen","flushUnknown")

# This is an example of eliminating flushOpen and flushUnknown and replacing them with flushSeptic and flushPit
res1<-slide(data=read.csv("data/InputFile.csv"),precision=0.001,moved="all",fromColumns=c("flushOpen_urb","flushUnknown_urb"),toColumns=c("flushSeptic_urb","flushPit_urb"),context="urban")
res2<-slide(data=res1,precision=0.001,moved="all",fromColumns=c("flushOpen_rur","flushUnknown_rur"),toColumns=c("flushSeptic_rur","flushPit_rur"),context="rural")
rowSums(res2[,c(13:25)])
rowSums(res2[,c(36:48)])

# This is an example of sliding the green button to the left by 10% in both urban and rural settings
res3<-slide(data=read.csv("data/InputFile.csv"),precision=0.001,moved=0.1,fromColumns=c("flushSeptic_urb","flushPit_urb","flushOpen_urb","flushUnknown_urb"),toColumns=c("flushSewer_urb"),context="urban")
res4<-slide(data=res3,precision=0.001,moved=0.1,fromColumns=c("flushSeptic_rur","flushPit_rur","flushOpen_rur","flushUnknown_rur"),toColumns=c("flushSewer_rur"),context="rural")
rowSums(res4[,c(13:25)])
rowSums(res4[,c(36:48)])

mverbyla/pathogenflows documentation built on Sept. 19, 2022, 10:05 p.m.