categorize | R Documentation |
Using a column within the data frame, categorize rows in a binary of yes or no, or customize with a set of category names. Data can be categorized based on the inclusion or lack of inclusion of parts of characters, or based on exact characters. Especially useful for turning ID tags into useful categories for analysis such as morphology, bleaching, taxonomy etc.
categorize(data, column, values, name, binary = TRUE, exact = TRUE, categories)
data |
The data frame. |
column |
The column name which contains the data on which to categorize rows. |
values |
The characters or parts of characters to use to classify rows. |
name |
The name of the now column of categories. |
binary |
If |
exact |
If |
categories |
The factor names denoting the presence of the characters or
parts of characters specified by |
A data frame with new categorization column.
Sites <- as.factor(c("One", "One", "One", "Two", "Two", "Three")) Transect <- as.factor(c("1-Deep", "1-Shallow", "2-Shallow", "1-Shallow", "1-Deep", "1-Deep")) Acropora.sp <- c(0.1, 0.6, 0.4, 0.9, 0.2, 0.5) Gardineroseris.sp <- c(0.4, 0.9, 0.5, 0.23, 0.5, NA) Psammocora.sp <- c(0.9, 0.6, 0.5, 0.8, 0.1, 0.4) Leptastrea.sp <- c(0.5, 0.7, 0.4, 0.8, 0.2, NA) Notes <- c(NA, NA, "saw octopus", NA, "white balance corrected", NA) coral_cover <- data.frame(Sites, Transect, Acropora.sp, Gardineroseris.sp, Psammocora.sp, Leptastrea.sp, Notes) # Classify shallow transects in a binary column categorize(data = coral_cover, column = "Transect", values = "Shallow", name = "Shallow", binary = TRUE, exact = FALSE) # Classify depth of transect in a new column based on transect name categorize(data = coral_cover, column = "Transect", values = c("Shallow", "Deep"), name = "Depth", binary = FALSE, categories = c("S", "D"), exact = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.