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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:35:22+00:00 2026-06-16T00:35:22+00:00

Is it possible to write a for loop with discrete levels? I have a

  • 0

Is it possible to write a for loop with discrete levels?

I have a vector of the following form:

a<-c(1,1,1,1,1,3,3,5,11,18 ....1350) 

it is an increasing series but does not follow any logical order;

I would like to run a for loop using levels(a) as an argument:

for i in 1:levels(a)

I get the following error:

In 1:levels_id :
 numerical expression has 1350 elements: only the first used
  • 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-16T00:35:23+00:00Added an answer on June 16, 2026 at 12:35 am

    Your initial mistake is that you are confusing looping over the index with looping over the elements of your vector.

    If you want to loop over unique elements of your vector then use:

    for(i in unique(a))
    

    I assume that’s what you wanted to do. But the alternative is to loop over the unique vector’s index:

    for(i in 1:length(unique(a))){
        this.a <- unique(a)[i]
    }
    

    These two are equivalent, but the second will enable you to know the current index as well (if you ever needed it).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to write multiple conditions in a while loop? If not, what
Possible Duplicate: In C++ why can't I write a for() loop like this: for(
Possible Duplicate: How to write a `for` loop over bool values (false and true)
Possible Duplicate: In C++ why can’t I write a for() loop like this: for(
My title is a bit confusing, but I'm trying to write a loop that
If I write a for, do, or while loop, is it possible to come
Possible Duplicate: do-while loop in Python? How do I write a loop in Python
Is it possible to write the following 'foreach' as a LINQ statement, and I
I don't know this is possible or not but let me ask you. How
Is it possible to write a loop that will write to the console with

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.