I have a problem with converting dates similar to this one: character string is not in a standard unambiguous format
I have retrieved information from a JSON to a list of data.frames, called "lista.alarmes". This is the value on the date field:
> lista.alarmes[[1]][[2]][8]
[1] "1578332914"
I'm able to convert it to a date format:
> d <- as.POSIXct(as.numeric(lista.alarmes[[1]][[2]][8]), tz="America/Sao_Paulo", origin="1970-01-01")
> str(d)
POSIXct[1:1], format: "2020-01-06 14:48:34"
Problem is when I try to save this value inside the original list. First thing, it looks like nothing has been updated
> lista.alarmes[[1]][[2]][8] <- d
> str(lista.alarmes[[1]][[2]][8])
chr "1578332914"
Also, I'm unable to retrieve information from that content
> year(lista.alarmes.2[[1]][[2]][8])
Error in as.POSIXlt.character(x, tz = tz(x)) :
character string is not in a standard unambiguous format
> year(as.POSIXct(lista.alarmes[[1]][[2]][8][[1]], origin="1970-01-01"))
Error in as.POSIXlt.character(x, tz, ...) :
character string is not in a standard unambiguous format
Why does the original list doesn't accept the value converted to as.POSIXct? I've tried with as.Date also, but similar results.
Further, I want to use lapply to proceed for all the list. I guess the command is fine, except for not achieving the update:
lista.alarmes <- lapply(lista.alarmes,function(x){
x[[2]][8] = as.POSIXct(as.numeric(x[[2]][8]), tz="America/Sao_Paulo", origin="1970-01-01")
return(x)})
EDIT: It seems like it is an issue spefic from dates. I've tried some other value and it worked fine:
> lista.alarmes[[1]][[2]][8] <- "test"
> lista.alarmes[[1]][[2]][8]
[1] "test"