-1

I have this character vector:

[1] "      USD(WorldTotal)"       "      JPY(WorldTotal)"      
[3] "      EURO(WorldTotal)"      "      KRW(WorldTotal)"      
[5] "      OTHER(WorldTotal)"     "         RUB(WorldTotal)"

and am trying to remove spaces from the vector.

I tried multiple ways to do this,

currency = trimws(currency)
currency = gsub("[[:blank:]]", "", currency)

none of which worked. I don't understand how this is the case. Could someone explain for me?

data = structure(list(currency = c("      USD (World Total)"      , 
NA, "      JPY (World Total)"      , NA, "      EURO (World Total)"      
), Types = c("Amounts(millionUSD)", "Share(%) (%)", "Amounts(millionUSD)", 
"Share(%) (%)", "Amounts(millionUSD)")), row.names = c(NA, -5L
), class = c("tbl_df", "tbl", "data.frame"))

the variable in question is `currency'.

Rainroad
  • 191
  • 8

1 Answers1

0

This should work:

data$currency <- trimws(data$currency, whitespace = "[\\h\\v\\t ]")
kashiff007
  • 376
  • 2
  • 12