[R] seconds to h:m:s format
Omar André Gonzáles Díaz
oma.gonzales at gmail.com
Thu Nov 12 00:15:17 CET 2015
Hi,
I've a data frame with 3 columns: "mes", "fuente", "avg.sessions.duration".
"avg.sessions.duration" is a column containing seconds.
I need you help with:
1.- Help to put these values in "h:m:s" format.
.
=======================================================
I've found this german page:
http://forum.r-statistik.de/viewtopic.php?f=25&t=5284
So I've tried:
for (i in 1:nrow(session.duration.fuente)) {
session.duration.fuente$avg.session.duration <-
format(as.POSIXct('0001-01-01 00:00:00') +
session.duration.fuente$avg.session.duration[i], "%H:%M:%S")
}
but got this error:
Error in unclass(e1) + unclass(e2) :
non-numeric argument to binary operator
=======================================================
After that I've tried: strptime:
session.duration.fuente$avg.session.duration <-
strptime(session.duration.fuente$avg.session.duration, "%H:%M:%OS")
But got NAs.
========================================================
Here is the data:
session.duration.fuente <- structure(list(mes = structure(c(1L, 1L, 1L, 1L,
1L, 2L, 2L,
2L, 2L, 2L), .Label = c("oct", "nov"), class = c("ordered", "factor"
)), fuente = c("adwords", "directo", "organico", "redes sociales",
"referral", "adwords", "directo", "organico", "redes sociales",
"referral"), avg.session.duration = c(970178, 1642455, 780485,
3170400, 179184, 352995, 833827, 260610, 2318928, 49836)), row.names =
c(NA,
-10L), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), vars = list(
mes), drop = TRUE, .Names = c("mes", "fuente", "avg.session.duration"
))
[[alternative HTML version deleted]]
More information about the R-help
mailing list