I am struggling with a very simple thing. I have a data frame in which the column Comments
contains information exclusive to single field observations (time in this case). For example:
data <- data.frame("Species" = c("TURPHI", "EMBHER", "ANTTRI"),
"Date" = c("2020/06/03", "2020/06/03", "2020/06/03"),
"Comments" = c("21:00;23:00;23:45", "22:01", "21:51"),
stringsAsFactors = FALSE)
> data
Species Date Comments
1 TURPHI 2020/06/03 21:00;23:00;23:45
2 EMBHER 2020/06/03 22:01
3 ANTTRI 2020/06/03 21:51
I have to split each row if it has more than 1 element in Comments
column. Elements are delimited by ;
. In the previous case, row 1 has to be splited into 3 rows, each with its time, such as:
> data
Species Date Time
1 TURPHI 2020/06/03 21:00
2 TURPHI 2020/06/03 23:00
3 TURPHI 2020/06/03 23:45
4 EMBHER 2020/06/03 22:01
5 ANTTRI 2020/06/03 21:51
Thanks a lot!!