如何更改R中的默认时区?
如何更改 R 中的默认时区? 我正在处理时间序列。我的所有时间序列都是在 UTC 时区中定义的,但如果我打印日期,它总是在 CET/CEST 时区中完成。
How can I change the default timezone in R?
I'm working with time series. All my time series are defined in UTC time zone, but if I print a date it is always done in CET/CEST time zone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
另一种无需更改整个计算机时间的方法是使用 setenv 命令,如下所示:
Sys.setenv(TZ='GMT')
Another way to do it, without changing the whole computer time is using the setenv command like this :
Sys.setenv(TZ='GMT')
请参阅这篇关于在 R 中更改时区的好文章:
http://blog.revolutionanalytics.com/2009 /06/converting-time-zones.html
很快(以防链接将来不可用):
See this good article on changing time zone in R:
http://blog.revolutionanalytics.com/2009/06/converting-time-zones.html
Shortly (in case the link will be unavailable in the future):
什么操作系统?
一般来说,请参阅
help(Startup)
,因为您可以通过.Renviron
及其站点范围的变体设置值。但是你可能应该为你的机器整体设置这个,在 Linux 下可能会改变文件
/etc/timezone
,而在 Windows 上你需要设置一个系统范围的环境变量TZ< /代码>。
最后,如果您的日期和时间的格式化显示显示CET/CEST,这可能已被设置为系统默认值,您的问题实际上是如何在 R 对象中正确设置 UTC 时间。
What operating system?
In general, see
help(Startup)
as you can set values via.Renviron
and its site-wide variant.But you should probably set this for your machine as a whole, which under Linux may alter the file
/etc/timezone
, and on Windows you'd set a system-wide environment variableTZ
.Lastly, if your formatted display of dates and time shows CET/CEST, this may already be set as a system default and your question really is how to set your UTC times correctly in your R objects.
我发现 @Dirk 的答案对 Ubuntu 非常有用,所以我想我会对其进行扩展。
从
help(Startup)
中我们看到环境变量是由Renviron.site
文件设置的:我们可以使用函数
R.home()
找到R_HOME
的路径,该函数在我的case 返回:因此,在
/usr/lib/R/etc/
中(对我来说)找到了Renviron.site
文件。只需打开此文件,然后插入行:
或类似内容。
I found @Dirk's answer very useful for Ubuntu, so I thought I would expand on it.
From
help(Startup)
we see that environment variables are set by theRenviron.site
file:We can find the path to
R_HOME
by using the functionR.home()
, which in my case returns:Therefore, the
Renviron.site
file is found (for me) in/usr/lib/R/etc/
.Simply open this file, and insert the line:
or similar.