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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:21:25+00:00 2026-06-19T03:21:25+00:00

I asked a question like this before but I decided to simplify my data

  • 0

I asked a question like this before but I decided to simplify my data format because I’m very new at R and didnt understand what was going on….here’s the link for the question How to handle more than multiple sets of data in R programming?

But I edited what my data should look like and decided to leave it like this..in this format…

X1.0   X X2.0 X.1
   0.9 0.9  0.2 1.2
  1.3 1.4  0.8 1.4

As you can see I have four columns of data, The real data I’m dealing with is up to 2000 data points…..Columns “X1.0” and “X2.0” refer “Time”…so what I want is the average of “X” and “X.1” every 100 seconds based on my 2 columns of time which are “X1.0” and “X2.0″…I can do it using this command

cuts <- cut(data$X1.0, breaks=seq(0, max(data$X1.0)+400, 400))
   by(data$X, cuts, mean)

But this will only give me the average from one set of data….which is “X1.0” and “X”…..How will I do it so that I could get averages from more than one data set….I also want to stop having this kind of output

cuts: (0,400]
[1] 0.7
------------------------------------------------------------ 
cuts: (400,800]
[1] 0.805

Note that the output was done every 400 s….I really want a list of those cuts which are the averages at different intervals…please help……I just used data=read.delim("clipboard") to get my data into the program

  • 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-19T03:21:27+00:00Added an answer on June 19, 2026 at 3:21 am

    It is a little bit confusing what output do you want to get.

    First I change colnames but this is optional

    colnames(dat) <- c('t1','v1','t2','v2')
    

    Then I will use ave which is like by but with better output. I am using a trick of a matrix to index column:

    matrix(1:ncol(dat),ncol=2)  ## column1 is col1 adn col2...
         [,1] [,2]
    [1,]    1    3
    [2,]    2    4
    

    Then I am using this matrix with apply. Here the entire solution:

    cbind(dat,
          apply(matrix(1:ncol(dat),ncol=2),2,
         function(x,by=10){      ## by 10 seconds! you can replace this 
                                 ## with 100 or 400 in you real data
         t.col <- dat[,x][,1]   ## txxx
         v.col <- dat[,x][,2]   ## vxxx
         ave(v.col,cut(t.col, 
                       breaks=seq(0, max(t.col),by)),
             FUN=mean)})
      )
    

    EDIT correct the cut and simplify the code

    cbind(dat,
         apply(matrix(1:ncol(dat),ncol=2),2,
               function(x,by=10)ave(dat[,x][,1], dat[,x][,1] %/% by)))
       X1.0   X X2.0 X.1       1         2
    1   0.9 0.9  0.2 1.2  3.3000  3.991667
    2   1.3 1.4  0.8 1.4  3.3000  3.991667
    3   2.0 1.7  1.6 1.1  3.3000  3.991667
    4   2.6 1.9  2.2 1.6  3.3000  3.991667
    5   9.7 1.0  2.8 1.3  3.3000  3.991667
    6  10.7 0.8  3.5 1.1 12.8375  3.991667
    7  11.6 1.5  4.1 1.8 12.8375  3.991667
    8  12.1 1.4  4.7 1.2 12.8375  3.991667
    9  12.6 1.8  5.4 1.2 12.8375  3.991667
    10 13.2 2.1  6.3 1.3 12.8375  3.991667
    11 13.7 1.6  6.9 1.1 12.8375  3.991667
    12 14.2 2.2  9.4 1.3 12.8375  3.991667
    13 14.6 1.8 10.0 1.5 12.8375 10.000000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've asked a question like this before but this one is different, this is
I feel like this question has been asked before but the answers seem pretty
I asked this question before which has got a very good response. But as
I asked this question before also but I didnt got any solution. I am
I have asked a similar question like this before but I am going to
I have asked a question like this before, and the answer was great but
A question like this was asked before and the person got nothing but criticisms,
I had asked a question similar to this before, but I have a new
I feel like this question must have been asked before but I must not
It's quite possible a question like this has been asked before, but I can't

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.