Learn R Programming

cmahalanobis (version 0.5.0)

cmanhattan: Calculate a Manhattan distance of a factor in a dataframe.

Description

This function takes a dataframe and a factor in input, and returns a matrix with the Manhattan distances about it.

Usage

cmanhattan(
  dataset,
  formula,
  plot = TRUE,
  plot_title = "Manhattan Distance Between Groups"
)

Value

A matrix containing distances.

Arguments

dataset

A dataframe.

formula

A factor which you want to calculate Manhattan distance.

plot

If TRUE, show a plot of distances.

plot_title

The title of plot.

Details

Calculate Manhattan distance

Examples

Run this code
# Example with iris dataset

cmanhattan(iris, ~Species, plot = TRUE, plot_title = "Manhattan Distance Between Groups")

# Example with mtcars dataset

cmanhattan(mtcars, ~am, plot = TRUE, plot_title = "Manhattan Distance Between Groups")

Run the code above in your browser using DataLab