strptime返回两个NAs,而它在之前和之后都可以正常工作

时间:2022-02-06 20:16:45

what am I doing wrong??

我做错了什么?

I use

我使用

    dates<- strptime(dataframe$Measurement.Time,"%d.%m.%Y %H:%M",tz="")

to convert the character strings into dates. This works perfectly on 14780 observations. But in two cases it returns NA.

将字符字符串转换为日期。这完全适用于14780次观测。但在两种情况下,它返回NA。

This is an example where it worked. The excerpts are both from the same resulting data frame.

这是一个例子。这些摘录都来自同一个结果数据框架。

head(dataframe.with.dates)
        date.time      Measurement.Time mü.mü.VWC.1 øC.Temp.1
1 2000-01-10 00:30:00  10.01.2000 0:30       -0.011      -0.6
2 2000-01-10 01:00:00  10.01.2000 1:00       -0.011      -0.6
3 2000-01-10 01:30:00  10.01.2000 1:30       -0.011      -0.6

This is an excerpt of my resulting data frame showing the two results where it went wrong:

这是我的结果数据框的一个摘录,显示了它出错的两个结果:

subset(dataframe.with.dates,is.na(dataframe.with.dates$date.time))
          date.time Measurement.Time  mü.mü.VWC   øC.Temp
    9572      <NA>  29.03.2015 2:00      -0.011      -0.6
    9573      <NA>  29.03.2015 2:30      -0.011      -0.6

where "date.time" is in POSIXlt and "Measurement.time" is the original date in character.

“日期。时间是正的,是度量的。时间是字符的原始日期。

I have checked the original .txt file where I got the data from but could not find any difference to the measurements above and below.

我已经检查了原始的.txt文件,在那里我得到了数据,但没有发现任何不同的测量上面和下面。

1 个解决方案

#1


3  

Googling "daylight savings time 3/29/2015" shows that this was the date of the spring shift to daylight savings time in Europe, e.g.: https://www.timeanddate.com/news/time/europe-starts-dst-2015.html

在谷歌上搜索“夏令时3/29/2015”显示,这是欧洲春季转向夏令时的日期,例如:https://www.timeanddate.com/news/time/time/europe-starts -dst-2015.html

Time zones are a nightmare: I would have thought using tz="CET" would do the trick, but it doesn't. strptime(mt,"%d.%m.%Y %H:%M",tz="UTC+01:00") doesn't complain, but it creates the times in UTC. It might be easiest to use tz="GMT" and pretend the times are standard even if they're not ...

时区是一场噩梦:我本以为使用tz="CET"就能达到目的,但事实并非如此。strptime(% d % m mt。”%Y %H:%M,tz="UTC+01:00")没有抱怨,但它在UTC中创建了时间。使用tz="GMT"可能是最简单的,即使时间不是标准的,也要假装时间是标准的。

I'm sure there are duplicates, but it's easier to answer your question than to find them (I did spend a few minutes trying).

我肯定有重复的,但是回答你的问题比找到它们更容易(我确实花了几分钟的时间尝试)。

#1


3  

Googling "daylight savings time 3/29/2015" shows that this was the date of the spring shift to daylight savings time in Europe, e.g.: https://www.timeanddate.com/news/time/europe-starts-dst-2015.html

在谷歌上搜索“夏令时3/29/2015”显示,这是欧洲春季转向夏令时的日期,例如:https://www.timeanddate.com/news/time/time/europe-starts -dst-2015.html

Time zones are a nightmare: I would have thought using tz="CET" would do the trick, but it doesn't. strptime(mt,"%d.%m.%Y %H:%M",tz="UTC+01:00") doesn't complain, but it creates the times in UTC. It might be easiest to use tz="GMT" and pretend the times are standard even if they're not ...

时区是一场噩梦:我本以为使用tz="CET"就能达到目的,但事实并非如此。strptime(% d % m mt。”%Y %H:%M,tz="UTC+01:00")没有抱怨,但它在UTC中创建了时间。使用tz="GMT"可能是最简单的,即使时间不是标准的,也要假装时间是标准的。

I'm sure there are duplicates, but it's easier to answer your question than to find them (I did spend a few minutes trying).

我肯定有重复的,但是回答你的问题比找到它们更容易(我确实花了几分钟的时间尝试)。