I have following dataset, which H means Hour and M means minutes.
PT8H10M
PT20M
I want to convert them to minutes, and the result will be
490
20
CodePudding user response:
Try this
dat <- c("PT8H10M", "PT20M")
dat <- gsub("^PT|M$","", dat )
sapply( strsplit(dat, "H"), function(x)
ifelse( length(x)==2, as.numeric(x[1])*60 as.numeric(x[2]), x ) )
[1] "490" "20"