R:将 ts 对象转换为 xts 对象时语言发生变化

R : language changes when converting ts object to xts object

我尝试将内置的时间序列sunspots数据转换成一个xts对象打印出来,代码如下:

sunspots.xts <- as.xts(sunspots)
sunspots.xts

结果是这样的

enter image description here

这是我的 sessionInfo() 输出:

R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=Chinese (Traditional)_Taiwan.950 LC_CTYPE=Chinese (Traditional)_Taiwan.950
[3] LC_MONETARY=Chinese (Traditional)_Taiwan.950 LC_NUMERIC=C
[5] LC_TIME=Chinese (Traditional)_Taiwan.950

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] xts_0.9-7 zoo_1.7-14 timeDate_3012.100

loaded via a namespace (and not attached):
[1] tools_3.3.2 grid_3.3.2 lattice_0.20-34 

月份现在是用繁体中文写的,但我希望输出保留为英文。我的 R 环境完全是英文的。我想 xts 不知何故知道我的操作系统 (win 8) 在繁体中文中工作,并决定将月份的表达方式更改为繁体中文。网站上有类似的讨论,我试过以下方法:

None 其中有效。我认为这是因为问题有些不同。非常感谢您的帮助。谢谢你。

作为 ,您需要更改区域设置。如果您将 LC_TIME 更改为 "C",时间将以英文打印。

# Save current LC_TIME
def.locale <- Sys.getlocale("LC_TIME")

# Set LC_TIME=ja_JP.UTF-8
Sys.setlocale(category = "LC_TIME", locale = "ja_JP.UTF-8")
sunspots.xts <- as.xts(sunspots)
head(sunspots.xts)
#           [,1]
#  1月 1749 58.0
#  2月 1749 62.6
#  3月 1749 70.0
#  4月 1749 55.7
#  5月 1749 85.0
#  6月 1749 83.5

# Set LC_TIME=C
Sys.setlocale(category = "LC_TIME", locale = "C")
head(sunspots.xts)
#          [,1]
# Jan 1749 58.0
# Feb 1749 62.6
# Mar 1749 70.0
# Apr 1749 55.7
# May 1749 85.0
# Jun 1749 83.5

# Set locale back
Sys.setlocale(category = "LC_TIME", locale = def.locale)