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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:48:36+00:00 2026-06-07T05:48:36+00:00

how can I split the following data.frame df <- data.frame(var1 = c(a, 1, 2,

  • 0

how can I split the following data.frame

df <- data.frame(var1 = c("a", 1, 2, 3, "a", 1, 2, 3, 4, 5, 6, "a", 1, 2), var2 = 1:14)

into lists of / groups of

a 1
1 2
2 3
3 4

a 5
1 6
2 7
3 8
4 9
5 10
6 11

a 12
1 13
2 14

So basically, value “a” in column 1 is the tag / identifier I want to split the data frame on. I know about the split function but that means I have to add another column and since, as can be seen from my example, the size of the groups can vary I do not know how to automatically create such a dummy column to fit my needs.

Any ideas on that?

Cheers,

Sven

  • 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-07T05:48:37+00:00Added an answer on June 7, 2026 at 5:48 am

    You could find which values of the indexing vector equal “a”, then create a grouping variable based on that and then use split.

    df[,1] == "a"
    # [1]  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
    #[13] FALSE FALSE
    cumsum(df[,1] == "a")
    # [1] 1 1 1 1 2 2 2 2 2 2 2 3 3 3
    split(df, cumsum(df[,1] == "a"))
    #$`1`
    #  var1 var2
    #1    a    1
    #2    1    2
    #3    2    3
    #4    3    4
    #
    #$`2`
    #   var1 var2
    #5     a    5
    #6     1    6
    #7     2    7
    #8     3    8
    #9     4    9
    #10    5   10
    #11    6   11
    #
    #$`3`
    #   var1 var2
    #12    a   12
    #13    1   13
    #14    2   14
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Do MySQL have any function by which I can split data of a column
Suppose I have the following data frame > df <- data.frame(var1 = c(A, B,
I try to understand the regex in python. How can i split the following
How can I split a string such as Mar10 into Mar and 10 in
I have a csv file with following sample data. o-option(alphabetical) v-value(numerical) number1,o1,v1,o2,v2,o3,v3,o4,v4,o5,v5,o6,v6 number2,o1,v11,o2,v22,o3,v33,o44,v44,o5,v55,o6,v66 and
What can I use to perform fast serialization of data into several files in
I have the following data (from a text file), I would like to split
I understand that nltk can split sentences and print it out using the following
Say I have the following data Name Value =============== Small 10 Medium 100 Large
Let's say I'd like to split some data into 60-character parts and store them

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.