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

  • Home
  • SEARCH
  • 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 5932987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:54:39+00:00 2026-05-22T14:54:39+00:00

I need to split/divide up a continuous variable into 3 equal sized groups. Example

  • 0

I need to split/divide up a continuous variable into 3 equal sized groups.

Example data frame:

das <- data.frame(anim = 1:15,
                  wt = c(181,179,180.5,201,201.5,245,246.4,
                         189.3,301,354,369,205,199,394,231.3))

After being cut up (according to the value of wt), I would need to have the 3 classes under the new variable wt2 like this:

> das 
   anim    wt wt2
1     1 181.0   1
2     2 179.0   1
3     3 180.5   1
4     4 201.0   2
5     5 201.5   2
6     6 245.0   2
7     7 246.4   3
8     8 189.3   1
9     9 301.0   3
10   10 354.0   3
11   11 369.0   3
12   12 205.0   2
13   13 199.0   1
14   14 394.0   3
15   15 231.3   2

This would be applied to a large data set.

  • 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-05-22T14:54:40+00:00Added an answer on May 22, 2026 at 2:54 pm

    try this:

    split(das, cut(das$anim, 3))
    

    if you want to split based on the value of wt, then

    library(Hmisc) # cut2
    split(das, cut2(das$wt, g=3))
    

    anyway, you can do that by combining cut, cut2 and split.

    UPDATED

    if you want a group index as an additional column, then

    das$group <- cut(das$anim, 3)
    

    if the column should be index like 1, 2, …, then

    das$group <- as.numeric(cut(das$anim, 3))
    

    UPDATED AGAIN

    try this:

    > das$wt2 <- as.numeric(cut2(das$wt, g=3))
    > das
       anim    wt wt2
    1     1 181.0   1
    2     2 179.0   1
    3     3 180.5   1
    4     4 201.0   2
    5     5 201.5   2
    6     6 245.0   2
    7     7 246.4   3
    8     8 189.3   1
    9     9 301.0   3
    10   10 354.0   3
    11   11 369.0   3
    12   12 205.0   2
    13   13 199.0   1
    14   14 394.0   3
    15   15 231.3   2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to split a list into two equal lists. For Example: I have
I need to split one variable into 3 variables. For example I have a
I need to split a number into even parts for example: 32427237 needs to
I have a string that I need split into smaller strings with an equal
I need to split an flv file into chunks of the known size on
I need to split my string input into an array at the commas. Is
I need to split a string into chunks of 2,2,3,3 characters and was able
In C# I need to split a string (a log4j log file) into array
I have a long string (multiple paragraphs) which I need to split into a
I need to split long string into a array with following constrains: The input

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.