Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

Calculate elapsed time using datatime data in R

$
0
0

I'm working on a clinical dataset in which samples were taken from subjects after taking a dose of a medication. The datetime column for samples and doses were provided in the following format directly from the clinical data base.

The intended output is to create a column for the elapsed time after dose (i.e.: Sample.Time - Dose.Time). The output can be in minutes or hours. N.B: we need to use both date and time because sampling can occur is a different date than dosing.

Sample.Time         Dose.Time
2019-06-07T08:23    2019-06-07T07:53
2019-06-07T08:53    2019-06-07T07:53
2019-06-07T09:23    2019-06-07T07:53
2019-06-07T09:53    2019-06-07T07:53
2019-06-07T10:23    2019-06-07T07:53
2019-06-07T10:53    2019-06-07T07:53
2019-06-07T11:53    2019-06-07T07:53
2019-06-07T13:53    2019-06-07T07:53
2019-06-07T15:53    2019-06-07T07:53
2019-06-07T17:53    2019-06-07T07:53

Intended Output is to create "Time.After.Dose"

Sample.Time          Dose.Time         Time.After.Dose
2019-06-07T08:23    2019-06-07T07:53    0.5
2019-06-07T08:53    2019-06-07T07:53    1
2019-06-07T09:23    2019-06-07T07:53    1.5
2019-06-07T09:53    2019-06-07T07:53    2
2019-06-07T10:23    2019-06-07T07:53    2.5
2019-06-07T10:53    2019-06-07T07:53    3
2019-06-07T11:53    2019-06-07T07:53    4
2019-06-07T13:53    2019-06-07T07:53    6
2019-06-07T15:53    2019-06-07T07:53    8
2019-06-07T17:53    2019-06-07T07:53    10
2019-06-07T19:50    2019-06-07T07:53    11.95
2019-06-08T07:43    2019-06-07T07:53    23.83333333
2019-06-09T07:43    2019-06-07T07:53    47.83333333
2019-06-12T07:43    2019-06-07T07:53    119.8333333

Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>