I'm used to use trimws
to get rid of any blank spaces on text.
Now I've a df that was made with scraped data.
I've 2 columns that relate to money but are chr vectors because they where scraped from a web, as mentioned before. To one column I can apply trimws
with no problem, but not to the other one.
str(lacuracao_tvs$precio_actual[1])
chr " 1199.00"
Why?
new_precio_actual <- trimws(lacuracao_tvs$precio_actual[1])
dput(new_precio_actual)
" 1199.00"
trimws works in precio_antes but not in precio_actual:
> str(lacuracao_tvs)
'data.frame': 100 obs. of 4 variables:
$ ecommerce : chr "la-curacao" "la-curacao" "la-curacao" "la-curacao" ...
$ producto : chr "TV LED AOC Ultra HD Smart 50\" LE50U7970" "TV Samsung Ultra HD 4K Smart 58\" UN-58RU7100G" "TV LG Ultra HD 4K Smart AI 55\" 55UK6200" "TV AOC Ultra HD 4K Smart 55\" 55U6285" ...
$ precio_antes : chr "1899.00" "1899.00" "1899.00" "1899.00" ...
$ precio_actual: chr " 1199.00" " 1199.00" " 1199.00" " 1199.00" ...
SessionInfo:
Sys.info()
sysname release version nodename
"Windows" "10 x64" "build 17763" "DESKTOP-MNDUKBD"
machine login user effective_user
"x86-64" "OGONZALES" "OGONZALES" "OGONZALES"
> sessionInfo(package = NULL)
R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_0.7.8 rvest_0.3.2 xml2_1.2.0 RSelenium_1.7.5
loaded via a namespace (and not attached):
[1] Rcpp_1.0.0 rstudioapi_0.9.0 bindr_0.1.1 magrittr_1.5
[5] rappdirs_0.3.1 tidyselect_0.2.5 R6_2.3.0 rlang_0.3.1
[9] stringr_1.3.1 httr_1.4.0 caTools_1.17.1.1 tools_3.5.2
[13] binman_0.1.1 selectr_0.4-1 semver_0.2.0 subprocess_0.8.3
[17] yaml_2.2.0 openssl_1.1 assertthat_0.2.0 tibble_2.0.1
[21] crayon_1.3.4 bindrcpp_0.2.2 purrr_0.2.5 bitops_1.0-6
[25] curl_3.3 glue_1.3.0 wdman_0.2.4 stringi_1.2.4
[29] compiler_3.5.2 pillar_1.3.1 XML_3.98-1.20 jsonlite_1.6
[33] pkgconfig_2.0.2
UPDATE 1:
utf8ToInt(lacuracao_tvs$precio_actual[1])
[1] 160 49 49 57 57 46 48 48