Unable to Substract two columns in R

I can see the two columns in question

Note that these are character type ("chr")

So first you want to convert these to datetime objects before you can subtract them. The lubridate function ymd_hms() can help with this. Load lubridate with library(lubridate). Then you will want to wrap each of your columns with this function before you subtract them.

Secondly, to access a column of data in R, where the data frame is called df and the column is called foo, then the notation you want is df$foo, and not df.foo.

I would give you the code to work this out, but I'm typing on my phone and it's tricky to write code, so if you can have a go at piecing these two hints together and reporting back your findings, you'll save me from logging on to a computer.

Good luck.

1 Like