In Order to get minute from timestamp in R we will be using as.numeric () and Format() function. Let’s see how to get minute from timestamp in R with an example.
Let’s first create the dataframe.
### Create Data Frame df1 = data.frame ( Name =c('Annie','Catherine','Teresa','Peterson','Richard','joe'), Login_time = as.POSIXct(c('2018-06-03 19:40:00','2018-06-03 11:30:30','2018-06-03 2:04:13','2018-06-03 16:44:43','2018-06-03 7:14:43','2018-06-03 17:12:41')), Logout_time = as.POSIXct(c('2018-06-03 21:40:34','2018-06-03 12:40:10','2018-06-03 3:44:23','2018-06-03 17:34:13','2018-06-03 9:34:23','2018-06-03 18:32:41'))) df1
dataframe df1 will be
Get Minute from timestamp in R
Minute is extracted from timestamp (column: Logout_time) using as.numeric () and Format() functions as shown below.
df1$Minute_component <- as.numeric(format(df1$Logout_time,'%M')) df1
So the resultant data frame has a column Minute_component with Minute extracted from timestamp.