Cyrillic transliteration in R

时光毁灭记忆、已成空白 提交于 2019-12-02 08:46:20

问题


Are there packages for Cyrillic text transliteration to Latin in R? I need to convert data frames to Latin to use factors. It is somewhat messy to use Cyrillic factors in R.


回答1:


I have found the package at last.

> library(stringi)
> stri_trans_general("женщина", "cyrillic-latin")

[1] "ženŝina"

> stri_trans_general("женщина", "russian-latin/bgn")

[1] "zhenshchina"

After that, the only issue remaining is the "ё" letter.

> stri_trans_general("Ёж", "russian-latin/bgn")

[1] "Yëzh"

I had to remove all the "ё" letters

> iconv(stri_trans_general("ёж", "russian-latin/bgn"),from="UTF8",to="ASCII",sub="")

[1] "yzh"

Or one can just remove the 'Ё' and 'ё' letters before

> gsub('ё','e',gsub('Ё','E','Ёжики на ёлке'))

[1] "Eжики на eлке"

or after transliteration.




回答2:


It is possible to do it with stringi package as you above, but with different transform identifier, for Serbian latin:

`stri_trans_general("жшчћђ", "Serbian-Latin/BGN")`

All characters should be transformed correctly to Serbian latin.




回答3:


If afterwards one uses Base R to filter the data in Cyrillic, one get's all NA's, but if dplyr is used then everything is fine.



来源:https://stackoverflow.com/questions/48575399/cyrillic-transliteration-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!