I can't figure out how to instruct R to change the columns "created_at" and "deadline" into date format. I don't recognize a date/time pattern in the numbers.
Asked
Active
Viewed 76 times
-3
-
1Please don't upload code, results or data as images for [these reasons](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557). – Limey May 04 '22 at 12:07
-
We also don't know what `kicstart` looks like, so it's difficult to help you. Please see here for how to ask a good R question on Stack Overflow: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Andrea M May 04 '22 at 15:47
-
@Limey I will keep that in mind for future posts. Thanks – Noha Sayedalahl May 05 '22 at 11:13
-
Hello @AndreaM the variables "created_at" and "deadline" should be dates. If it helps, this dataset is supposed to represent data gathered in 02-2022. Thanks. – Noha Sayedalahl May 05 '22 at 11:24
1 Answers
0
Assuming the numbers represent seconds from some origin (perhaps 1970-01-01 00:00:00), you can use as.POSIXct()
:
as.POSIXct(1240456019, origin="1970-01-01 00:00:00")
# [1] "2009-04-22 23:06:59 EDT"
as.POSIXct(1242467940, origin="1970-01-01 00:00:00")
# [1] "2009-05-16 05:59:00 EDT"
To do this to the entire variable, do:
kickstart$created_at = as.POSIXct(kickstart$created_at, origin="1970-01-01 00:00:00")
kickstart$deadline = as.POSIXct(kickstart$deadline, origin="1970-01-01 00:00:00")

DaveArmstrong
- 18,377
- 2
- 13
- 25
-
I tried your suggestion with different origin dates 1982 and 1975. Surprisingly I get the same dates for both origin dates which is puzzling. – Noha Sayedalahl May 05 '22 at 11:40
-
'head(kickstart$created_at)' 1370358703 1363533018 'kickstart$created_at = as.POSIXct(kickstart$created_at, origin = "1982-01-01 00:00:00")' 'head(kickstart$created_at)' "2025-06-04 15:11:43 UTC" "2025-03-17 15:10:18 UTC" 'kickstart$created_at = as.POSIXct(kickstart$created_at, origin = "1975-01-01 00:00:00")' 'head(kickstart$created_at)' "2025-06-04 15:11:43 UTC" "2025-03-17 15:10:18 UTC" – Noha Sayedalahl May 05 '22 at 11:46
-
I get two different results: `x <- c(1370358703, 1363533018)`, then ` as.POSIXct(x, origin = "1982-01-01 00:00:00")` gives me `"2025-06-04 11:11:43 EDT" "2025-03-17 11:10:18 EDT"` and `as.POSIXct(x, origin = "1975-01-01 00:00:00")` gives me `"2018-06-04 11:11:43 EDT" "2018-03-17 11:10:18 EDT"` – DaveArmstrong May 05 '22 at 15:11