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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:03:42+00:00 2026-06-14T20:03:42+00:00

How can I write a fast function, that will partitionate a dataframe in 4

  • 0

How can I write a fast function, that will

  • partitionate a dataframe in 4 parts of the same length w,x,y,z
  • return the per-index mean of w,x,y,z
    this mean should be m=(w+x+y+z)/4 (note that these are letters all vectors)

Example data may look like this:

# my data + noise 4 times
a <- 1:1000 + rnorm(10)
b <- 1:1000 + rnorm(10)
c <- 1:1000 + rnorm(10)
d <- 1:1000 + rnorm(10)

mydf <- data.frame(time=1:4000, measurement=c(a,b,c,d))

Till now I use the following slow workaround. And apply the function on mydf$measurement

AvgOverPeriodsVector <- function(hdata, recordedperiods=4){
  SamplesPerPeriod <- length(hdata)/recordedperiods
  a <- unname(sapply((split(hdata, rep(1:SamplesPerPeriod,recordedperiods))),mean ))
  return(a)
}

How can I improve the speed?

Would rowMean like in
Element-wise mean in R
be faster?

  • 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-14T20:03:42+00:00Added an answer on June 14, 2026 at 8:03 pm

    Just found a hint about .rowMeans here. I guess this is a good solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone please tell me how I can write a bash shell script that
Can someone please explain how you can write a url pattern and view that
So I know I can write my own HTML-encoding function like this: function getHTMLEncode(t)
I'm attempting to write an app that can arrange timed playback of some (mostly
Write a branchless function that returns 0, 1, or 2 if the difference between
I want to write a function that takes an int between 1 and 64,
I have to write fast right-trimming function in C. My first attempt to do
You can write //google.com instead of http://google.com and https://google.com where // is relative to
I can write an assertion message one of two ways. Stating success: assertEquals( objects
We can write CSS as the following types: Inline CSS Embedded CSS External CSS

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.