In my dataset have a column named duration. From it I want to split the hours and minutes into 2 separate columns. If either hours or minutes is not there want to add 0h or 0m accordingly.
Provided the same existing column details as well as the expected new columns in the below attached image:
train <- read.csv("sampledata.csv", stringsAsFactors = F)
train$Duration
Edit:
sampledata <- data.frame(
emp_id = c (1:5),
Duration = c("10h 50m","5h 34m","9h","4h 15m","23m"),
stringsAsFactors = FALSE
)
sampledata$Duration