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"))
Marwah Al-kaabi
  • 419
  • 2
  • 7

3 Answers3

1
library(stringr)
df$ID <- str_replace(df$ID, " ", "")
df
Bloxx
  • 1,495
  • 1
  • 9
  • 21
1
library(dplyr)
df <- df %>% mutate(ID = gsub(" ","",ID))
ekolima
  • 588
  • 4
  • 8
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
  • 4,244
  • 1
  • 8
  • 18