I have words, Genus species, and I want an underscore to replace the space between the two strings in R
Input:
>data$species
Genus species
You should use gsub
:
data$species <- gsub(" ", "_", data$species)
We can use sub
from base R
data$species <- sub(" ", "_", data$species)
Or with chartr
from base R
data$species <- chartr(" ", "_", data$species)
Or using tidyverse
library(tidyverse)
data %>%
mutate(species = str_replace(species, " ", "_"))