全部,
我在 Azure 机器学习上使用 R,我遇到了一些问题。
我想用程序R计算两个日期之间的差异,例如2014/11/01和2014/11/03。
我使用 R 中的函数“strptime”来做这件事,它可以在我自己的电脑上运行,但是当我想在 Azure ml 上运行相同的代码时,出现了错误。
错误是:
[ModuleOutput] 1: In strptime(x, format, tz = tz) :
[ModuleOutput]
[ModuleOutput] unable to identify current timezone 'C':
[ModuleOutput]
[ModuleOutput] please set environment variable 'TZ'
[ModuleOutput]
[ModuleOutput] 2: In strptime(x, format, tz = tz) : unknown timezone 'localtime'
我认为问题是它无法检测到 Azure ml 上的时区,但我不确定。
有什么办法可以解决这个问题吗?
提前致谢。
我想你遇到了类似这篇文章的问题:How to define current time zone in Azure ML for strptime function, unknown timezone 'localtime'
一个可能的解决方案是在调用 strptime 之前使用 Sys.setenv(TZ=‘UTC’)。
要在Azure机器学习上用R语言计算两个日期之间的差异,可以使用difftime函数。此函数将两个日期时间对象作为参数,并默认返回以秒为单位的差异。您可以使用 units 参数指定其他单位,例如天或周。
比如你想计算2014/11/01和2014/11/03的天数之差,可以用这个代码:
# Convert strings to date-time objects
date1 <- as.POSIXct("2014/11/01", format = "%Y/%m/%d")
date2 <- as.POSIXct("2014/11/03", format = "%Y/%m/%d")
# Calculate the difference in days
difftime(date2, date1, units = "days")
这将返回 2 天作为结果。