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
We can use sub from base R
sub
base R
data$species <- sub(" ", "_", data$species)
Or with chartr from base R
chartr
data$species <- chartr(" ", "_", data$species)
Or using tidyverse
tidyverse
library(tidyverse) data %>% mutate(species = str_replace(species, " ", "_"))