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

  • Home
  • SEARCH
  • 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 8083477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:29:22+00:00 2026-06-05T17:29:22+00:00

i have a question how to select certain values from a table. I have

  • 0

i have a question how to select certain values from a table. I have a table with times and values and i want to get the row below and after a certain time.

Example-Data.Frame.

Time   Value
02:51  0.08033405 
05:30  0.43456738 
09:45  0.36052075 
14:02  0.45013807 
18:55  0.05745870
....# and so on

Time is coded as character, but can be formatted.
Now i have for example the time “6:15” and want to get the values of the time before and after this time from the table (0.43456738 and 0.36052075).
The database is in fact quite huge and i have a lot of time values.
Anyone has a nice suggestion how to accomplish this?

thanks
Curlew

  • 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-05T17:29:23+00:00Added an answer on June 5, 2026 at 5:29 pm
    value_before <- example_df[which(example_df$time=="09:45")-1, ]$value
    value_after <- example_df[which(example_df$time=="09:45")+1, ]$value
    
    # This could become a function
    
    return_values <- function(df,cutoff) {
    value_before <- df[which(df$time==cutoff)-1, ]$value
    value_after <- df[which(df$time==cutoff)+1, ]$value
    return(list(value_before, value_after))
    }
    
    return_values(exmaple_df, "09:15")
    

    # A solution for a large dataset.

    library(data.table)
    df <- data.frame(time = 1:1000000, value = rnorm(1000000))
    # create a couple of offsets
    df$nvalue <- c(df$value[2:dim(df)[1]],NA)
    df$pvalue <- c(NA,df$value[2:dim(df)[1]])
    new_df <- data.table(df)
    setkey(new_df,"time")
    
    new_df[time==10]
     time      value     pvalue     nvalue
    [1,]   10 -0.8488881 -0.1281219 -0.5741059
    
    
    > new_df[time==1234]
         time      value   pvalue     nvalue
    [1,] 1234 -0.3045015 0.708884 -0.5049194
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a question how to use an alias from a select query: $timecheck
hopefully a pretty simple question this time. I have a Select method in a
I have a question about the extraction of multiple values from a data.frame in
I have question i.e how can i select a previous div CODE:- if($i >
I have a question for Alfresco Community v4.0.0 I create content rule, select execute
The question I have is kind of simular to this one - MySQL select
I have a simple question about the expression in jquery to select a class
I have a small sql question for you. I have two queries: SELECT tbl_CostPrevisions.Month,
Consider I have such SQL query: SELECT t1.* FROM table1 t1 LEFT JOIN table2
Hey guys, quick question, I have an id that is applied multiple times on

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.