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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:14:09+00:00 2026-06-02T17:14:09+00:00

Here is my problem: myvec <- c(1, 2, 2, 2, 3, 3,3, 4, 4,

  • 0

Here is my problem:

myvec <- c(1, 2, 2, 2, 3, 3,3, 4, 4, 5, 6, 6, 6, 6, 7, 8, 8, 9, 10, 10, 10)

I want to develop a function that can caterize this vector depending upon number of categories I define.

if categories 1 all newvec elements will be 1

if categories are 2 then

unique (myvec), i.e.

1 = 1, 2 =2, 3 = 1, 4 = 2, 5 =1, 6 = 2, 7 = 1, 8 = 2, 9 = 1, 10 = 2

(which is situation of odd or even numbers)

If categories are 3 then first three number will be 1:3 and then pattern will be repeated.

1 = 1, 2 = 2, 3=3, 4=1, 5 = 2, 6 = 3, 7 =1, 8 = 2, 9 = 3, 10 =1 

If caterogies are 4 then first number will be 1:4 and then pattern will be repeated

1 = 1, 2 = 2, 3= 3, 4 = 4, 5 = 1, 6 = 2, 7=3, 8=4, 9 =1, 10 = 2

Similarly for n categories the first 1:n, then the pattern repeated.

  • 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-02T17:14:11+00:00Added an answer on June 2, 2026 at 5:14 pm

    Using the recycling features of R (this gives a warning if the vector length is not divisible by n):

    R> myvec <- c(1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 6, 6, 6, 7, 8, 8, 9, 10, 10, 10)
    R> n <- 3
    R> y <- cbind(x=sort(unique(myvec)), y=1:n)[, 2]
    R> y
     [1] 1 2 3 1 2 3 1 2 3 1
    

    or using rep:

    R> x <- sort(unique(myvec))
    R> y <- rep(1:n, length.out=length(x))
    R> y
     [1] 1 2 3 1 2 3 1 2 3 1
    

    Update: you could just use the modulo operator

    R> myvec
     [1]  1  2  2  2  3  3  3  4  4  5  6  6  6  6  7  8  8  9 10 10 10
    R> n <- 4
    R> ((myvec - 1) %% n) + 1
     [1] 1 2 2 2 3 3 3 4 4 1 2 2 2 2 3 4 4 1 2 2 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maddening problem here. When my page loads: <body onload=getClientDateTime();> It runs this function: document.getElementById('ClientDateTime').value=hello
I am having problem here with bitmaps..I want to remove the black background that
date here my problem: String datetime = 2012-03-24 23:20:51; I know that that string
I have a problem here I can't solve. I have a database of houses
enter code here My problem is this: in this database the junction table contains
I have a problem here with this code. I'm opening a socket, then listening
I've got some problem with my function and don't know how to solve this
PROBLEM: Here's the code: import matplotlib.pyplot as plt plt.bar([1,2],[5,4]) plt.title('this is a very long
My problem here is that I would like to pass an object to a
Having a weird problem here. Everybody knows that if you use web.config's customErrors section

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.