-2

I am attempting to "cut" my data frame according Times (by 10 min).

dat <- read.table(text="Time
4:30:08 AM
3:37:00 PM
5:15:38 PM
5:16:41 PM
5:17:05 PM
5:17:25 PM
5:48:48 PM", header=TRUE, sep="\t")

I want it be like this:

Time        Group
4:30:08 AM  4:30
3:37:00 PM  3:30
5:15:38 PM  5:10
5:16:41 PM  5:10
5:17:05 PM  5:10
5:17:25 PM  5:10
5:48:48 PM  5:50

Thanks!

IRTFM
  • 258,963
  • 21
  • 364
  • 487
AsSAASA
  • 35
  • 8
  • 1
    Try `df1$Group <- format(as.POSIXct(cut(strptime(df1$Time, '%I:%M:%S %p'), breaks='10 min')),'%I:%M')` – akrun Jul 21 '15 at 19:08
  • 1
    Based on the entries in Time column and corresponding Group, wouldn't the last one be `5:40`? – akrun Jul 21 '15 at 19:34

1 Answers1

1

Using the edit for input that I made to the question:

> dat$Group <- paste0(substr(dat$Time,1,3), "0")
> dat
        Time Group
1 4:30:08 AM  4:30
2 3:37:00 PM  3:30
3 5:15:38 PM  5:10
4 5:16:41 PM  5:10
5 5:17:05 PM  5:10
6 5:17:25 PM  5:10
7 5:48:48 PM  5:40

Admittedly we don't know for sure what the data actually looks like but I thought it unlikely that the poster had it in an actual R datetime or time class. At least this may provoke some clarification.

IRTFM
  • 258,963
  • 21
  • 364
  • 487