R as.POSIXct错误可以';我找不到窃听器

R as.POSIXct错误可以';我找不到窃听器,r,date,time,timestamp,posixct,R,Date,Time,Timestamp,Posixct,我正在尝试将我的日期和时间转换为R记录的格式,以便对我的数据进行排序。我有一个与以前的数据集一起工作的代码,但在这里,我一生都找不到它不工作的原因。这可能很简单,但我得到了v。沮丧的 这是我试图在名为DataLHB的数据集上运行的代码: head(DataLHB) date_hour month_num animal_id name sex Receiver detection_count presence_flag 1 2009060912 6

我正在尝试将我的日期和时间转换为R记录的格式,以便对我的数据进行排序。我有一个与以前的数据集一起工作的代码,但在这里,我一生都找不到它不工作的原因。这可能很简单,但我得到了v。沮丧的 这是我试图在名为DataLHB的数据集上运行的代码:

head(DataLHB)
        date_hour month_num animal_id   name sex Receiver detection_count presence_flag
       1 2009060912         6        42 Ellama   F   101739               1             1
       2 2009060912         6       224  Pokey   F       NA               0             0
       3 2009060913         6        42 Ellama   F   101739               5             1
       4 2009060913         6       224  Pokey   F   101739              11             1     
代码是

sDataLHB <- split(DataLHB, DataLHB$name) ##order the data by individual names
sDataLHB <- lapply(sDataLHB, function(Ind) {
  Ind <- subset(Ind, presence_flag == 1, select = date_hour)
  Ind <- within(Ind, {
   year <- substring(date_hour, 1, 4)
   month <- substring(date_hour, 5, 6)
   day <- substring(date_hour, 7, 8)
   H <- substring(date_hour, 9, 10)
   M <- S <- "00"
   datehour<-paste(paste(year, month, day, sep = "-"),
           paste(H, M, S, sep = ":"))
   RTime <- as.POSIXct(datehour)
   })
  Ind
 })

 **Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format** 
但这只给了我警告

    There were 18 warnings (use warnings() to see them)
    Warning messages:
    1: In `[<-.data.frame`(`*tmp*`, nl, value = structure(list( ... : replacement element 1 has 1 row to replace 0 rows
    2: In `[<-.data.frame`(`*tmp*`, nl, value = structure(list( ... : replacement element 2 has 1 row to replace 0 rows
    3: In `[<-.data.frame`(`*tmp*`, nl, value = structure(list( ... : replacement element 3 has 1 row to replace 0 rows
共有18个警告(使用warnings()查看它们)
警告信息:

1:在“[不确定你需要这个凌乱的
sDataLHB
做什么,为什么不干脆
as.POSIXct(DataLHB$date\u hour,format=“%Y%m%d%H”)
?我同意David的观点。当我尝试只使用你函数的内部部分时(只在data.frame上运行你所有的正则表达式,而不是转换成一个列表,然后使用它),工作正常--没有错误。感谢您的回复。此代码是一个更大代码的一部分,我需要为以后的部分创建
sDataLHB
。我以前将此代码应用于另一个类似的数据集,它工作得非常好,我只是不明白在这种情况下,
as.POSIXct
,我希望有人一个相似但坚定的经历。。。
    There were 18 warnings (use warnings() to see them)
    Warning messages:
    1: In `[<-.data.frame`(`*tmp*`, nl, value = structure(list( ... : replacement element 1 has 1 row to replace 0 rows
    2: In `[<-.data.frame`(`*tmp*`, nl, value = structure(list( ... : replacement element 2 has 1 row to replace 0 rows
    3: In `[<-.data.frame`(`*tmp*`, nl, value = structure(list( ... : replacement element 3 has 1 row to replace 0 rows