0

Can you please help me to remove a space from the ID column in my data? I have data frame like this:

df<-data.frame(
  "ID" = c("G 249485", "L 938495", "N 234987"), type=c("a","b","c"))

3 Answers3

1
library(stringr)
df$ID <- str_replace(df$ID, " ", "")
df
Bloxx
  • 1,407
  • 1
  • 6
  • 19
1
library(dplyr)
df <- df %>% mutate(ID = gsub(" ","",ID))
ekolima
  • 358
  • 3
  • 6
1

or

library(dplyr)

df %>%
    dplyr::mutate(ID = stringr::str_remove(ID, pattern = "\\s"))

       ID type
1 G249485    a
2 L938495    b
3 N234987    c
DPH
  • 3,362
  • 1
  • 6
  • 16