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 9051663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:57:44+00:00 2026-06-16T12:57:44+00:00

I have a data set that needs a lot of cleaning up in the

  • 0

I have a data set that needs a lot of cleaning up in the formatting, and at some point I would like to calculate the time that people in the study spent fishing. This would be easy if the times that fishing started and stopped were in a normal format, but for some reason the data are not in a useful decimal format. For example, 10:45 in the morning is recorded as 10.45, while 11:10 would be 11.10.

I have already tried asking Excel to replace all periods with colons (it won’t do it, and others have already tried to help me make Excel cooperate). I can think of a couple of approaches to doing this in R but am not sure how to proceed with either. First, if there was some way to divide the part after the decimal (ONLY) by 60 then the decimal format would make sense. Then, 10.45 would be 10.75 and subtraction would be no problem. Or, it would also work to just write some kind of simple code to replace the periods with colons and then (I’m thinking?) manipulate it using something like the chron package.

I do not know how you would code either of these options – does anyone have any suggestions? I think dividing by 60 could be accomplished with function that broke apart the pieces before and after the period (like the opposite of paste) but I can’t find the name of such a function. The first one would also be simpler I imagine, although the second one would actually probably shed light on a larger problem I have with R, which is trying to figure out how to make commands generalizable. I understand how I could force it to change all of the 10.45 to 10:45, but wish I knew if there was a format just to say “take XX.XX and change to XX:XX” no matter what the actual digits were. But one thing at a time I suppose.

  • 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-06-16T12:57:45+00:00Added an answer on June 16, 2026 at 12:57 pm

    In the absence of an example, I present as.difftime for this, :

    > d <- as.difftime('10.45', format='%H.%M')
    > d
    Time difference of 10.75 hours
    > as.numeric(d)
    [1] 10.75
    

    For your comment, you must ensure that you read the time values as strings.

    Time.Start = c(9.10, 9.10, 9.10, 9.10, 9.10, 9.10)
    Time.Stop = c(14.25, 14.25, 14.25, 14.25, 14.25, 14.25)
    

    Turn them into character strings. It would be much better to just read them as strings in the first place, but we can kludge them with sprintf:

    Time.Stop <- sprintf('%.2f', Time.Stop)
    Time.Start <- sprintf('%.2f', Time.Start)
    

    Then parse and take the difference. - is returning an object of class difftime, similar to above.

    strptime(Time.Stop, format='%H.%M') - strptime(Time.Start, format='%H.%M')
    
    ## Time differences in hours
    ## [1] 5.25 5.25 5.25 5.25 5.25 5.25
    ## attr(,"tzone")
    ## [1] ""
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data set that that I would like to call in a
I have a set of data that is structured like this: ItemA.GroupA ItemB.GroupA ItemC.GroupB
I have a php script that needs to run for quite some time. What
I have a decent sized set of data that needs to be stored in
I have a set of 'dynamic data' that I need to bind to the
I have a data set that resembles this: id product_id size color price created_date
I have a data set that is around 700 rows with eight columns of
I have the following data set that I am trying to plot with ggplot2,
I have a large data set that I'm working with in excel. About 1000+
I have a very large possible data set that I am trying to visualize

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.