Learn R Programming

MonoInc (version 1.1)

monotonic: Monotonic Check

Description

This function can check the monoticity of a single vector, matrix, or data.frame that has multiple IDs within the matrix or data.frame.

Usage

monotonic(data, id.col=NULL, y.col=NULL, direction)

Arguments

data
a data.frame or matrix or vector of measurement data
id.col
column where the id's are stored; default is NULL
y.col
column where y values, or measurements are stored; default is NULL
direction
the direction of the function a choice between increasing 'inc', and decreasing 'dec'

Value

If the user enters a vector, the function returns TRUE or FALSE as to where that particular vector is monotonic increasing or not, it returns NA if the vector has missing values. If the user enters a matrix or data frame, the function returns a matrix with 2 columns. The first column as the id. The second column as a 0 for FALSE and 1 for TRUE as to where the data in that particular id is monotonic increasing or not, or NA if the y column has missing values in that particular id.

Examples

Run this code
data(simulated_data)
## Run monotonic
test <- monotonic(simulated_data, 1,3, direction='inc')

## look at the number of ids that are non-monotonic
table(as.logical(test[,2]))

##to ignore NA values
x<-c(1,2,3,5,NA,7,8)
monotonic(na.omit(x), direction='inc')

Run the code above in your browser using DataLab