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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:36:55+00:00 2026-06-09T14:36:55+00:00

Sorry guys if this is a noob question. I need help on how to

  • 0

Sorry guys if this is a noob question.
I need help on how to loop over my dataframe.Here is a sample data.

a <- c(10:29);
b <- c(40:59);
e <- rep(1,20);
test <- data.frame(a,b,e)

I need to manipulate column “e” using the following criteria for values in column “a”

for all values of

“a” <= 15, “e” = 1,

“a” > 15 & < 20, “e” = 2

“a” > 20 & < 25, “e” = 3

“a” > 25 & < 30, “e” = 4 and so on to look like this

result <- cbind(a,b,rep(1:4, each=5))

My actual data frame is over 100k long. Would be great if you could sort me out here.

  • 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-09T14:36:56+00:00Added an answer on June 9, 2026 at 2:36 pm
    data.frame(a, b, e=(1:4)[cut(a, c(-Inf, 15, 20, 25, 30))])
    

    Update:

    Greg’s comment provides a more direct solution without the need to go via subsetting an integer vector with a factor returned from cut.

    data.frame(a, b, e=findInterval(a, c(-Inf, 15, 20, 25, 30)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry guys for noob question, need help. I'm try to use Sharekit - https://github.com/ShareKit/ShareKit
Sorry for this guys, but I really am unlucky today. Please help, my problem
Sorry guys , need to bring my old question back from the dead as
sorry guys, asked a bit wrongly, here is the EDIT got a simple question,
I'm sorry if this comes through as a noob question, but I'm really stuck
Hey guys sorry this is a pretty long question but I cannot call printPASSInfo()
First of all sorry guys for posting the question here. The support forum seems
Sorry guys if this is a lame question, but the examples i found dont
Sorry guys, if this is a stupid question. I have a set of integers
Sorry guys, I posted this earlier today where my add as linked images were

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.