I am looking to remove the space after the string, for example instead of my vector value being SO MILWAUKEE .xlsx
I would like it to be SO MILWAUKEE.xlsx
. I am open to a solution in dplyr or base r
[1] "INTERLINE BRANDS.xlsx" "POLY-AMERICA, LP.xlsx" "SO TTI POWER EQUIPMENT .xlsx"
[4] "GENERAC SO.xlsx" "SO TOTER LLC .xlsx" "SO IMPERIAL INDUSTRIAL .xlsx"
[7] "SO MTDARNOLD PRODUCTS .xlsx" "SO KOHLER GENS.xlsx" "RUBBERMAID CONSUMER .xlsx"
[10] "SO MILWAUKEE .xlsx" "SO CINDERELLA INC .xlsx" "MAKITA .xlsx"
[13] "SO THE TORO COMPANY .xlsx" "SO RUBBERMAID SPECIALTY.xlsx" "SO AMES TRUE TEMPER , I.xlsx"
[16] "SO POLYWOOD .xlsx" "ZEPENFORCER.xlsx" "TIGER SUPPLIES .xlsx"
[19] "INTERLINE BRANDS, INC..xlsx" "SO MWE INVESTMENTS, LLC.xlsx" "SO DIMPLEX NORTH AMERIC.xlsx"
CodePudding user response:
Let's say your data is in dat
. You could do the following:
dat <- gsub("\\s \\.xlsx", ".xlsx", dat)
CodePudding user response:
library(tidyverse)
data <-
c("INTERLINE BRANDS.xlsx", "POLY-AMERICA, LP.xlsx", "SO TTI POWER EQUIPMENT .xlsx",
"GENERAC SO.xlsx", "SO TOTER LLC .xlsx", "SO IMPERIAL INDUSTRIAL .xlsx",
"SO MTDARNOLD PRODUCTS .xlsx", "SO KOHLER GENS.xlsx", "RUBBERMAID CONSUMER .xlsx",
"SO MILWAUKEE .xlsx", "SO CINDERELLA INC .xlsx", "MAKITA .xlsx",
"SO THE TORO COMPANY .xlsx" , "SO RUBBERMAID SPECIALTY.xlsx", "SO AMES TRUE TEMPER , I.xlsx" ,
"SO POLYWOOD .xlsx", "ZEPENFORCER.xlsx", "TIGER SUPPLIES .xlsx",
"INTERLINE BRANDS, INC..xlsx", "SO MWE INVESTMENTS, LLC.xlsx", "SO DIMPLEX NORTH AMERIC.xlsx")
str_replace(data, '\\s \\.xlsx', '.xlsx')
#> [1] "INTERLINE BRANDS.xlsx" "POLY-AMERICA, LP.xlsx"
#> [3] "SO TTI POWER EQUIPMENT.xlsx" "GENERAC SO.xlsx"
#> [5] "SO TOTER LLC.xlsx" "SO IMPERIAL INDUSTRIAL.xlsx"
#> [7] "SO MTDARNOLD PRODUCTS.xlsx" "SO KOHLER GENS.xlsx"
#> [9] "RUBBERMAID CONSUMER.xlsx" "SO MILWAUKEE.xlsx"
#> [11] "SO CINDERELLA INC.xlsx" "MAKITA.xlsx"
#> [13] "SO THE TORO COMPANY.xlsx" "SO RUBBERMAID SPECIALTY.xlsx"
#> [15] "SO AMES TRUE TEMPER , I.xlsx" "SO POLYWOOD.xlsx"
#> [17] "ZEPENFORCER.xlsx" "TIGER SUPPLIES.xlsx"
#> [19] "INTERLINE BRANDS, INC..xlsx" "SO MWE INVESTMENTS, LLC.xlsx"
#> [21] "SO DIMPLEX NORTH AMERIC.xlsx"
Created on 2021-12-06 by the reprex package (v2.0.1)