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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:08:23+00:00 2026-05-18T04:08:23+00:00

Ok, the title may not be the most descriptive. It’s easier to explain with

  • 0

Ok, the title may not be the most descriptive. It’s easier to explain with an example.

I have a data.frame like this:

A B 1 2
L M 3 0
P Q 5 6

I want to output an array of the cell in column 1 if col3 > col4, or the cell in col2 if col3 <= col4. The output vector from this data.frame would be B, L, Q.

I’m aware that I still haven’t explained my problem very well, so here is what it would look like in an imperative language:

vector = []
for each rows as row
  if row[3] > row[4]
    vector.add(row[1])
  else
    vector.add(row[2])
return vector

I apologise if this problem has already been answered, but unfortunately Google is not much of help when it comes to R questions.

Thanks,
Andreas

  • 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-18T04:08:24+00:00Added an answer on May 18, 2026 at 4:08 am

    This should work (assuming df is your data frame)

    apply(df, 1, function(x){ifelse(x[3] > x[4], x[1], x[2])})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The title may not seem very clear - was not sure how to explain
Sorry the title may not be very clear. Basically I have a wrapper for
The title may have been confusing, but please let me explain: Currently when I
My title may make my question sound confusing, but it is not. I have
The title may not really explain what I'm really trying to get at, couldn't
this may be easy for most of you .. but not me. I am
Okay the question title may not have made sense... mostly because I don't know
In advance, I apologize if the question title may not be be convenient. I'm
That title may need some work. Perhaps after reading this, you may be able
The element tasklist may contain at most one title and at most one description

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.