I have a data frame named "enrolments":
enrolled_at, unenrolled_at and fully_participated_at are factors. I want to add a new column to my data frame that indicates the differences in hours between two non-empty attributes. The type of this new column is not important, but it must show time in this format (HH MM SS).
I want to do following pseudo code:
If (unenrolled_at == empty && fully_participated_at != empty)
newAttributeValue = fully_participated_at - enrolled_at
else if (unenrolled_at != empty && fully_participated_at == empty)
newAttributeValue = unenrolled_at - enrolled_at
else
do nothing
Edit: I tried all methods in the site to do this but they does not work. Times stored as factor class in my dataframe but solutions in the site are factor - factor or (String) time - (String) time. I also tried "as.character" and "as.Date" functions respectively. So my question is not duplicate. Rolando Tamayo offers different method to solve my problem but it gives me error: "Error in ymd_hms(comments$unenrolled_at) : could not find function "ymd_hms"" ( I installed lubridate package)