Skip to contents

Using two vectors, change the values in one column to a new set of values. Helpful if you need to change many values at once, like updating changes to site names or taxonomy.

Usage

change_values(data, column, from, to)

Arguments

data

A data frame.

column

The column in which to change values.

from

A vector containing the values you wish to change.

to

A vector contain the values you want to change to, ensuring these occur in the same order as the from vector.

Value

A data frame containing new values within the specified column.

Examples

Sites <- c("One.jpg", "Two.jpg", "Three.jpg", "Four.jpg", "Five.jpg")
Dominant_Coral <- c("Acropora.sp", "Leptastrea.spp", "Acropora.sp",
                    "Acropora.sp", "Acropora.sp")
Dominant_Cover <- c(0.1, 0.4, 0.9, 0.2, 0.5)
Largest_Coral <- c("Acropora.sp", "Acropora.sp", "Psammocora.sp",
                   "Acropora.sp","Gardineroseris.spp")

coral_cover <- data.frame(Sites, Dominant_Coral, Dominant_Cover, Largest_Coral)

change_values(coral_cover, "Dominant_Coral",
    c("Acropora.sp","Leptastrea.spp"), c("Acropora_tabulate", "Leptastrea.purpurea"))
#>       Sites      Dominant_Coral Dominant_Cover      Largest_Coral
#> 1   One.jpg   Acropora_tabulate            0.1        Acropora.sp
#> 2   Two.jpg Leptastrea.purpurea            0.4        Acropora.sp
#> 3 Three.jpg   Acropora_tabulate            0.9      Psammocora.sp
#> 4  Four.jpg   Acropora_tabulate            0.2        Acropora.sp
#> 5  Five.jpg   Acropora_tabulate            0.5 Gardineroseris.spp