[英]removing unicode characters from data frame in r
I have a large data frame which contains farsi characters I import it in r with this code: 我有一个大型数据框,其中包含我用以下代码导入它的波斯语字符:
Sys.setlocale(locale = "persian")
dt <- read.csv("data.csv",encoding="UTF-8")
and my dt is like this: 我的dt是这样的:
id title
3376971 چوب شور آلبينا شيرين عسل <U+06F3><U+06F0> گرمي
3376989 ويفر رنگارنگ مينو <U+06F1><U+06F4>.<U+06F5> گرمي
3376990 کوکي مينو <U+06F3><U+06F0> گرمي
3376991 بيسکويت هاي باي شيرين عسل <U+06F3><U+06F8> گرمي
3376992 شکلات توريستي آناتا <U+06F2><U+06F8> گرمي
3376993 اسنک مغزدار شکلاتي شونيز <U+06F1><U+06F7> گرمي
3376994 شکلات فندقي آناتا <U+06F1><U+06F8> گرمي
3376995 نان روغني شيرين عسل <U+06F5><U+06F0> گرمي
3376996 بيسکويت هاي باي شيرين عسل <U+06F5><U+06F7> گرمي
There are some unicode which I'd like to remove, I have tried: 我想删除一些unicode,我试过:
dt<- cbind.data.frame(dt$id,gsub("<.+>", "", dt$title)
dt<- cbind.data.frame(dt$id,gsub("\\S+\\s+|-", "", dt$title)
dt<- cbind.data.frame(dt$id,gsub("^\\s*<U\\+\\w+>\\s*", "", dt$title)
dt<- cbind.data.frame(dt$id,gsub("\\<U[^\\>]*\\>", "", dt$title)
dt<- cbind.data.frame(dt$id,gsub(""▼|▲"", "", dt$title)
but non of them works 但不是他们的作品
I also tried this: 我也试过这个:
dt$title<-gsub("^\\s*<U\\+\\w+>\\s*", "", dt$title)
but I got this error: 但是我收到了这个错误:
Error in `$<-.data.frame`(`*tmp*`, title, value = character(0)) :
replacement has 0 rows, data has 66366
I noticed that in R console my data are shown like this: 我注意到在R控制台中我的数据显示如下:
چوب شور آلبینا شیرین عسل ۳۰ گرمی
and the Unicode has been shown like Persian numbers and I tried this and it worked: 并且Unicode已经显示为波斯数字,我试过这个并且它有效:
dt$title<-gsub("[۰-۹]+", "", dt$title)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.