Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7034963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:14:54+00:00 2026-05-28T01:14:54+00:00

I have question about grouping data into specific categories. Generally, if I have a

  • 0

I have question about grouping data into specific categories.

Generally, if I have a factor variable, I would perform something like below to bucket/recode the data into a preferred pattern:

educ = NA
educ[educ2 %in% levels(educ2)[c(5,8)]] <- "HS or Some College"
educ[educ2 %in% levels(educ2)[2:3]] <- "College Degree"
educ[educ2 %in% levels(educ2)[c(4,6)]] <- "Advanced Degree" 
educ[educ2 %in% levels(educ2)[c(1,7,9)]] <- NA
educ = factor(educ)

However, I’m struggling with trying to regroup a factor variable, TIME, which has 10,000 + levels. The data is structured as follows:

> levels(wj$time)
    [1] "0:00:05"  "0:00:07"  "0:00:08"  "0:00:10"  "0:00:13"  "0:00:15"  "0:00:18"  "0:00:23"  "0:00:31"  "0:00:34"  "0:00:36" 
   [12] "0:00:39"  "0:00:41"  "0:00:47"  "0:00:48"  "0:00:54"  "0:00:55"  "0:00:56"  "0:00:59"  "0:01:01"  "0:01:02"  "0:01:03" 
   [23] "0:01:13"  "0:01:17"  "0:01:31"  "0:01:33"  "0:01:41"  "0:01:44"  "0:01:48"  "0:01:50"  "0:01:52"  "0:01:53"  "0:01:55" 
   [34] "0:02:08"  "0:02:12"  "0:02:13"  "0:02:21"  "0:02:26"  "0:02:27"  "0:02:30"  "0:02:32"  "0:02:33"  "0:02:36"  "0:02:37" 
   [45] "0:02:38"  "0:02:43"  "0:02:45"  "0:02:53"  "0:02:56"  "0:03:07"  "0:03:15"  "0:03:19"  "0:03:21"  "0:03:22"  "0:03:24" 
   [56] "0:03:30"  "0:03:36"  "0:03:39"  "0:03:41"  "0:03:49"  "0:03:56"  "0:03:59"  "0:04:02"  "0:04:04"  "0:04:07"  "0:04:10" 
   [67] "0:04:11"  "0:04:12"  "0:04:14"  "0:04:16"  "0:04:17"  "0:04:19"  "0:04:22"  "0:04:27"  "0:04:28"  "0:04:30"  "0:04:37" 
   [78] "0:04:39"  "0:04:41"  "0:04:49"  "0:04:51"  "0:04:52"  "0:04:53"  "0:04:54"  "0:05:05"  "0:05:06"  "0:05:20"  "0:05:22" 

I’m just not sure how to quickly bucket the data into specific brackets when there are so many factor levels. I’d like to group them into perhaps 0:12:00 to 0:05:00 and 0:05:01 to 0:10:00 and so forth. With so many factor levels, I’m just a little lost on how to identify when to start and end bucketing. Can anyone provide any help? With 10,000 + buckets, this becomes an issue with how I would traditionally do things.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:14:54+00:00Added an answer on May 28, 2026 at 1:14 am

    You can split the timestamp into its components: the buckets are then very easy to compute.

    # Sample data
    n <- 10
    d <- data.frame(
      time = paste( 
        sample(0:23, n, replace=TRUE), 
        sample(0:59, n, replace=TRUE), 
        sample(0:59, n, replace=TRUE), 
        sep=":" 
      ),
      value = rnorm(n)
    )
    
    # Split the "time" column into its components
    d$time <- as.character( d$time )
    times <- strsplit( d$time, ":" )
    times <- lapply( times, as.numeric )
    times <- do.call(rbind, times)
    colnames(times) <- c("hour", "minute", "second")
    d <- cbind(times, d)
    
    # Build the buckets
    d$bucket <- paste(
      sprintf( "%02d:%02d:00", d$hour, floor( d$minute / 5 ) * 5 ),
      sprintf( "%02d:%02d:59", d$hour, floor( d$minute / 5 ) * 5 + 4 ),
      sep=" to "
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about how to deploy WPF application into a PC without
Have a question about stored procedure: How to retrieve the variable's value from stored
I have a question about a particular query I'd like to execute against a
I have question about global variable in Objective-C. I have two .m files :
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have question about normalization. Suppose I have an applications dealing with songs. First
I have a question about using streams in .NET to load files from disk.
I have a question about best practices regarding how one should approach storing complex
I have a question about locking. This doesn't have to be only about record
I have a question about using os.execvp in Python. I have the following bit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.