对 R 中的语言环境设置感到困惑 [英] Confused with the locale settings in R

查看:26
本文介绍了对 R 中的语言环境设置感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚才我回答了这个 在 R 中删除欧元符号后的字符 问题.但它不适用于我的 r 代码适用于使用 Ubuntu 的其他人.

Just now I answered this Removing characters after a EURO symbol in R question. But it's not working for me where the r code works for others who are on Ubuntu.

这是我的代码.

x <- "services as defined in this SOW at a price of € 15,896.80 (if executed fro"
euro <- "\u20AC"
gsub(paste(euro , "(\\S+)|."), "\\1", x)
# "" 

我认为这就是更改区域设置的全部内容,我不知道该怎么做.

I think this is all about changing the locale settings, I don't know how to do that.

我在 Windows 8 上运行 rstudio.

I'm running rstudio on Windows 8.

> sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

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  
[7] base     

loaded via a namespace (and not attached):
[1] tools_3.2.0

@Anada 的回答很好,但是每次在正则表达式中使用 unicode 时,我们都需要添加 encoding 参数.有什么办法可以在 Windows 上将默认编码修改为 utf-8 吗?

@Anada's answer is good but we need to add that encoding parameter for every time when we use unicodes in regex. Is there any way to modify the default encoding to utf-8 on Windows?

推荐答案

好像是编码有问题.

考虑:

x <- "services as defined in this SOW at a price of € 15,896.80 (if executed fro"
gsub(paste(euro , "(\\S+)|."), "\\1", x)
# [1] ""
gsub(paste(euro , "(\\S+)|."), "\\1", `Encoding<-`(x, "UTF8"))
# [1] "15,896.80"

这篇关于对 R 中的语言环境设置感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆