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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:33:33+00:00 2026-06-13T05:33:33+00:00

struggling with this one : Sample data : foo <- structure(c(1, 1, 1, 1,

  • 0

struggling with this one :
Sample data :

    foo <- structure(c("1", "1", "1", "1", "1", "1", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "C", "C", "C", NA, NA, NA, NA, "C",
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "C",
"C", NA, NA, NA, NA, NA, "C", "C", "C", "C", "C", "C", "C", "C",
"C", "C", "C", NA, NA, NA, NA, "C", "C", "C", "C", "C", "C",
"C", "C", NA, NA, NA, NA, NA, NA, NA, NA, "C", "C", "C", NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "C", "C", "C", NA, NA,
NA, NA, NA, "C", "C", NA, NA, NA, NA, NA, "C", "C", "C", NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "C", "C", NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "C", "C", "C", "C",
"C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C",
"C", NA, NA, "C", "C", "C", "C", "C", NA, "C", "C", "C", "C",
"C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C",
"C", "C", NA, NA, "C", "C", NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA), .Dim = c(15L, 13L), .Dimnames = list(NULL, c("weeks",
"vv", "rv", "ja", "aa", "bv", "aj", "vb", "rj", "rr", "vr", "bb",
"jr")))

How to group theses datas by weeks and apply rle function ? Expected output would be :

out <- structure(c("weeks", "1", "2", "vv", "1", "1", "rv", "0", "1",
"ja", "1", "1", "aa", "1", "1", "bv", "1", "0", "aj", "1", "1",
"vb", "1", "0", "rj", "1", "0", "rr", "1", "1", "vr", "2", "2",
"bb", "1", "1", "jr", "1", "0"), .Dim = c(3L, 13L), .Dimnames = list(
    NULL, NULL))

Tried so far :

test <- aggregate(foo, by=data.frame(foo[,1]), function(x,na.rm=T) rle(as.numeric(x))$values)

Gives me a list (as expected with rle) which I could then compute and try to get the expected output. But I’m sure there is a cleaner way to accomplish that… Any ideas ?

Thanks for looking !

  • 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-13T05:33:34+00:00Added an answer on June 13, 2026 at 5:33 am

    Apparently a bunch of ways to process the rle output; here’s another.

    d <- data.frame(foo)
    aggregate(!is.na(d[,-1]), d[,1,drop=FALSE], function(x) sum(rle(x)$values))
    #   weeks vv rv ja aa bv aj vb rj rr vr bb jr
    # 1     1  1  0  1  1  1  1  1  1  1  2  1  1
    # 2     2  1  1  1  1  0  1  0  0  1  2  1  0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im struggling with this one. I have a list of items and on a
Been struggling with this one I have the following DOM Structure: <ol id=add_images> <li>
I've been struggling with this one for a couple of days now. My current
Alright.. I'm struggling with this one.. I've got an image with a transparent hole
Hey, I'm really struggling with this one. I'am trying to port a small piece
I've been struggling for a while with this one; I'll try to explain it
I'm struggling to combine nohup, open_init_pty and sudo in a one-liner. Something like this:
I'm struggling with this one. I need to randomly keep X percent of a
I have been struggling with this one, hopefully it will help someone else. Whilst
This is a bit of a strange one, but I've been struggling for a

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.