Hello,
See if the following does what you need.
hours <- function(x, format = "%H:%M"){
as.integer(format(strptime(x, format = format), "%H"))
}
minutes <- function(x, format = "%H:%M"){
as.integer(format(strptime(x, format = format), "%M"))
}
x <- c("18:10", "19:43")
hours(x)
See ?strptime on how to handle time formats.
If you want to stay playing with strsplit: It actually returns a list,
hence you probably want to:
dt$hr <- sapply(tstamp, "[", 1)
Uwe Ligges
On 28.04.2013 13:48, Alexandre Karev wrote:
Hello!
I've time stamp ('time') field in dataset ('dt
Hello!
I've time stamp ('time') field in dataset ('dt') with values like "18:10",
"19:43",
I need to split time field into hour and minutes and add both as new
columns to dataset.
We are able to do it in bash+awk, but curious to stay within R codebase as
much as possible.
For now we are usin
3 matches
Mail list logo