0

I have data frame called load4 and column called "Loan.Length" which contains data like

"36 months" ,"36 months", "60 months" , "36 months" , "36 months" , "36 months"

i want to remove the white spaces in between them

i have tried

1.

str_replace( " ", "", load4$Loan.Length)

2.

 trimws(load4$Loan.Length, which = c("both"))

3.

trim.whitespace(load4$Loan.Length)

trim.whitespace(load4$Loan.Length) 

it has no error but the data remains the same :

"36 months", "36 months" ,"60 months", "36 months", "36 months", "36 months", "36 months"

Sabith
  • 1,628
  • 2
  • 20
  • 38
CrazyPanda
  • 27
  • 4
  • 4
    Have you assigned it back to the column `load4$Loan.Length <- trimws(load4$Loan.Length, which = c("both"))` – akrun Apr 14 '19 at 05:29
  • Possible duplicate of [How to remove all whitespace from a string?](https://stackoverflow.com/questions/5992082/how-to-remove-all-whitespace-from-a-string) – DJV Apr 14 '19 at 07:23

1 Answers1

0

Using tidyverse it would be.

load4 %>%
  mutate(Loan.Length = str_replace_all(Loan.Length, " ", ""))
pythonjokeun
  • 431
  • 2
  • 8