Q:

Plot the sum of a single column in R

I have a sample dataset named: data that looks like this:
                ID               TIMEDATA                     DURATION      
                A                12/18/2019 4:45:10 AM           
                A                12/18/2019 4:45:11 AM         1 sec
                A                12/18/2019 9:06:59 PM         0 sec             
                B                12/18/2019 4:14:13 AM         0 sec
                B                12/18/2019 4:14:14 AM         1 sec

I am wanting to create a barplot of the SUM of column 'DURATION' as it is associated with the timedata hour.
I have used this code, but this is not working.
              data$TIMEDATA <- as.Date(data$TIMEDATA, format = "%m/%d/%Y %I:%M:%S %p")

               data$TIMEDATA = format(data$TIMEDATA, "%I")
               tapply(data$DURATION, data$TIMEDATA, FUN = sum)

               barplot(tapply(data$DURATION, format(data$TIMEDATA, "%I"), FUN = sum))

        dput:

         Classes ‘tbl_df’, ‘tbl’ and 'data.frame':  617195 obs. of  3                    variables:
           $ ID: Factor w/ 57 levels "","A",..: 37 37 37 37 37 43 43 43 43 43 ...
           $ TIMEDATA  : chr  "04" "04" "04" "04" ...
           $ DURATION     : num  1 1 1 0 6 1 1 1 0 1 ...

Any help is appreciated.
I will continue to research this.

A:

If the 'DURATION' is numeric it would work
library(lubridate)
data$TIMEDATA <- format(mdy_hms(data$TIMEDATA), "%I")
barplot(tapply(data$DURATION, data$TIMEDATA, FUN = sum))

data
data <- structure(list(ID = c("A", "A", "A", "B", "B"), 
    TIMEDATA = c("12/18/2019 4:45:10 AM", 
"12/18/2019 4:45:11 AM", "12/18/2019 9:06:59 PM", "12/18/2019 4:14:13 AM", 
"12/18/2019 4:14:14 AM"), DURATION = c(0L, 1L, 0L, 0L, 1L)),
class = "data.frame", row.names = c(NA, 
-5L))

