【发布时间】:2016-05-22 05:33:20
【问题描述】:
我有两个看起来相同但不相同的字符串。
> t
[1] "2009_Manaus_Aerotáxi_crash"
> t2
[1] "2009_Manaus_Aerotáxi_crash"
> identical(t,t2)
[1] FALSE
> str(t)
chr "2009_Manaus_Aerotaxi_crash""| __truncated__
> str(t2)
chr "2009_Manaus_Aerotáxi_crash"
如何强制这两个字符串相等?
谢谢
【问题讨论】:
-
它们都是字符串吗?检查
str() -
这似乎是一个数据类型问题。你能提供给我们
dput(list(t=t,t2=t2))的输出吗? -
> dput(list(t=t,t2=t2)) 结构(list(t = "2009_Manaus_Aerotáxi_crash", t2 = "2009_Manaus_Aerotáxi_crash"), .Names = c("t", "t2 "))
-
charToRaw(t) [1] 32 30 30 39 5f 4d 61 6e 61 75 73 5f 41 65 72 6f 74 61 cc 81 78 69 5f 63 72 [26] 61 73 68 charToRaw(t2) [1] 32 30 30 39 5f 4d 61 6e 61 75 73 5f 41 65 72 6f 74 c3 a1 78 69 5f 63 72 61 [26] 73 68
-
见stackoverflow.com/questions/23699271/…,特别是`stri_trans_general(x, "Latin-ASCII")
标签: r string comparison