我正在寻找基于字符向量的两个小标题,但是在write.csv()
和read.csv()
之间发生了一些事情,使它们不相等。在下面的reprex中,str_cmp()
返回0
(“匹配”),但是在我的实际项目中,它返回了-1
(字符串不可比)。我不知道为什么会改变。
在任何情况下,str_cmp()
对我来说用处不大,因为dplyr::left_join
联接成相等的值并且不能与函数一起使用。
我如何更改这些字符串之一,以便str1==str2
返回TRUE
?我需要能够对整个字符向量执行此操作,以便可以执行以下操作:
dplyr::left_join(tibble1,tibble2,by = c("charVector1"="charVector2")
[charVector1
和charVector2
是从中拉出str1
和str2
的列。
#DL 19/10/30
## Tryna work out why these strings aren't the same
#####################################################################
#Get strings from GitHub repo ---------------------------------------
read.table(
"https://raw.githubusercontent.com/davelovellCARU/stringHelp/master/string1.txt"
) ->
str1
read.table(
"https://raw.githubusercontent.com/davelovellCARU/stringHelp/master/string2.txt"
) ->
str2
# The strings are not equal -----------------------------------------
str1 == str2
#> x
#> 1 FALSE
# But they look the same and the computer knows it ------------------
stringi::stri_cmp(str1, str2)
#> [1] 0
由reprex package(v0.3.0)创建于2019-10-30
知道了!
有一个执行此操作的整洁函数:stringclean::replace_non_asci(string)
我在两个字符串上都运行了,现在它们是相同的。只需将其卡入一个变异体中,小滴就会加入。