在R中获取英语的工作日 [英] Get weekdays in English in R

查看:116
本文介绍了在R中获取英语的工作日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在美国境外使用R,并且所有内容都可以用英语运行,但是weekdays()的结果仍然是西班牙语:

I am using R outside the US and I got everything working in English, but the result of weekdays() is still in Spanish:

Day <- seq(as.Date("2013-06-01"), by=1, len=30)
weekdays(Day)
[1] "sábado"    "domingo"   "lunes"     "martes"    "miércoles"  (...)

关于如何用英语获得工作日的任何想法吗?

Any ideas on how to get the weekdays in English?

推荐答案

DatePOSIX*t对象的打印似乎受LC_TIME语言环境类别控制.

Printing of Date and POSIX*t objects seems to be controlled by the LC_TIME locale category.

在Windows上,您可以这样更改:

On Windows, you change it like this:

## First, save the current value so we can restore it later
Sys.getlocale("LC_TIME")
# [1] "English_United States.1252"

## First in Spanish
Sys.setlocale("LC_TIME","Spanish Modern Sort")
# [1] "Spanish_Spain.1252"
weekdays(Sys.Date()+0:6)
# [1] "lunes"     "martes"    "miércoles" "jueves"    "viernes"   "sábado"   
# [7] "domingo"  

## Then back to (US) English
Sys.setlocale("LC_TIME","English United States")
# [1] "English_United States.1252"
weekdays(Sys.Date()+0:6)
# [1] "Monday"    "Tuesday"   "Wednesday" "Thursday"  "Friday"    "Saturday" 
# [7] "Sunday" 

在大多数* NIX上,等价于:

On most *NIXes, the equivalent would be:

Sys.setlocale("LC_TIME", "en_US")

特定的语言环境名称取决于操作系统,如?Sys.setlocale中所述.有关Windows接受的名称,请请参见此处.有关Linux接受的名称,请参见此处.

The particular locale names are OS-dependent, as mentioned in ?Sys.setlocale. For names accepted by Windows, see here. For names accepted by Linux, see here.

这篇关于在R中获取英语的工作日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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