I currently have a dataframe of stock KPIs and I would like to remove the "$" character from the data. However, I can only use one line of code in addition to the mandatory usage of the stringi package. Looking at the documentation, the "stri_replace_all_fixed" was the function that stood out to me, but upon running that function, my data frame lost its formatting. I tried combining both the lapply and the stri_replace_all_fixed functions to no avail. Pointers on how to address this problem would be much appreciated.
Asked
Active
Viewed 171 times
0
-
3Post an example dataset using `dput(head(yourdataframe))` – IRTFM Nov 13 '17 at 23:56
2 Answers
0
With library(stringi)
yourdataframe[] <- lapply(yourdataframe, stri_replace_all_regex,"\\$", "")
CER
- 784
- 7
- 20
0
# Dummy data
dta <- data.frame(group = rep(LETTERS[1:5], 10)) %>%
mutate(value = sample(1:10, 50, replace = TRUE) %>% paste("$"))
# scrub a dub (using dplyr)
dta %>% mutate_all(funs(stri_replace_all_fixed(., "$", "")))
and it is one of the faster approaches, too: replacement drag races
leerssej
- 12,592
- 5
- 45
- 53