An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110413/1dadd026/attachment.pl>
Time data
2 messages · Gregory Pierce, jim holtman
It depends on how you want to work with the data. Here is an example of converting both to POSIXct and a numeric value:
x <- c('1:24', '13:46')
# convert to POSIXct
x.POSIXct <- as.POSIXct(x, format = '%H:%M')
x.POSIXct
[1] "2011-04-14 01:24:00 EDT" "2011-04-14 13:46:00 EDT"
# to get a numeric value representing the hour x.hour <- do.call(rbind, strsplit(x, ":")) # create matrix # convert to numeric mode(x.hour) <- 'numeric' # convert to hour x.hour %*% c(1, 1/60)
[,1] [1,] 1.40000 [2,] 13.76667 On Wed, Apr 13, 2011 at 5:29 PM, Gregory Pierce
<pierce.gregory at gmail.com> wrote:
Hello fellow R-users, I have a data set that includes times in the hh:mm format. I am uncertain how to tell R that it is time data. Currently when I try to calculate a mean with this time subset, I get an error message:
mean(mar2011stats$TT)
[1] NA Warning message: In mean.default(mar2011stats$TT) : ?argument is not numeric or logical: returning NA TT is the column label under which I have stored my time data: (for example, 1:24 to represent one hour and twenty four minutes). Do I have to convert everything to minutes so that R can deal with it as it would other numerical values? Thanks, Greg ? ? ? ?[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Jim Holtman Data Munger Guru What is the problem that you are trying to solve?