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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:26:17+00:00 2026-06-07T15:26:17+00:00

I am using R to analyze data and I need to count how many

  • 0

I am using R to analyze data and I need to count how many consecutive values in a data frame belongs to a certain group. The group is given by the column “type”. Here is an example of my data. The date column won’t be used, it was useful just to order the rows.

                    date type
  2009-11-12 02:01:02    1
  2009-11-12 02:08:27    1
  2009-11-12 02:26:44    1
  2009-11-12 02:27:12    1
  2009-11-12 02:28:14    1
  2009-11-12 02:30:04    1
  2009-11-12 02:35:19    5
  2009-11-12 02:40:11    2
  2009-11-12 11:35:04    6
  2009-11-12 12:32:06    4
  2009-11-12 12:32:24    6
  2009-11-12 14:08:00    5
  2009-11-12 14:16:00    1
  2009-11-12 14:17:33    1

I know I can use ddply for example to summarize data. However I want summaries breaking up by changes in the column “type”. Applying ddply will give me something like this:

> df <- data.frame(x=c(1,1,1,1,1,1,5,2,6,4,6,5,1,1))
> ddply(df,c("x"),summarize,count=length(x))
  x    count
  ========
  1     8
  2     1
  4     1
  5     2
  6     2

Whereas, what I really want to achieve is this:

  x    count
  ========
  1     6
  5     1
  2     1
  6     1
  4     1
  6     1
  5     1
  1     2
  • 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-07T15:26:18+00:00Added an answer on June 7, 2026 at 3:26 pm

    The function you’re looking for is rle:

    df <- data.frame(x=c(1,1,1,1,1,1,5,2,6,4,6,5,1,1))
    > rle(df$x)
    Run Length Encoding
      lengths: int [1:8] 6 1 1 1 1 1 1 2
      values : num [1:8] 1 5 2 6 4 6 5 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using Stata to combine and analyze data for all of our agencies
I have been playing around with using graphs to analyze big data. Its been
I'm trying to analyze logs using splunk and I need to parse lines that
I need to analyze thousands of jpeg files (by retrieving it EXIF data). It
Being a programmer I occasionally find the need to analyze large amounts of data
I need to analyze tens of thousands of lines of data. The data is
I'm working on a project where I need to analyze Apache logs using SSAS.
I'm using HtmlAgilityPack to parse and analyze HTML pages, and I need to know
I am using Google App Engine mapreduce to analyze some data. I am generating
I am using Nokogiri to analyze some HTML, but, I don't know how get

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.