Решение с использованием sub () и gsub будет выглядеть так:
# first identify strings with "h"
h_in_str <- grepl("h", sampledata$Duration)
# if string has "h", then return all before "h" or else return 0
sampledata$Hours <- ifelse(h_in_str, sub("h.*", "", sampledata$Duration), 0)
# identify strings with "m"
m_in_str <- grepl("m", sampledata$Duration)
# if string has "m", return all numbers without those preceding "h" or else return 0
sampledata$Minutes <- ifelse(m_in_str,
gsub("([0-9]+).*$", "\\1", sub(".*h", "", sampledata$Duration)), 0)
Это даст вам данные, которые вы ищете
sampledata
emp_id Duration Hours Minutes
1 1 10h 50m 10 50
2 2 5h 34m 5 34
3 3 9h 9 0
4 4 4h 15m 4 15
5 5 23m 0 23