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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:59:46+00:00 2026-05-23T20:59:46+00:00

I have a data set with two columns of positive and negative numbers. I

  • 0

I have a data set with two columns of positive and negative numbers. I would like to create a third column that reflects which quadrant they would appear in if plotted in Cartesian space.

For example, if Column A is positive, and Column B is positive, then Column C would record “I.” If column A is negative, and Column B is negative, then Column C would record “III,” and so on.

I suspect I can do this with an if else function and then loop or apply it across rows in the data set, but my attempts to write the if else have so far failed.

  • 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-23T20:59:46+00:00Added an answer on May 23, 2026 at 8:59 pm

    Well, the following would give you values between 1 and 4:

    C <- (A<0) + (B<0)*2L + 1L
    

    This transforms the whole column in one go. The magic lies in that FALSE/TRUE is treated as 0/1, and you can do math on it. By using 2L and 1L instead of 2 and 1, you keep the result as integers instead of forcing a coercion to doubles (which is slower and takes more memory).

    Then assuming you want to map to these quadrants:

           +B
            |
         II | I
    -A -----+---- +A
        III | IV
            |
           -B
    

    You could use this (updated to use a data.frame):

    # Sample data.frame with columns a & b
    d <- data.frame(a=c(1,-1,-1,1), b=c(1,1,-1,-1))
    
    quadrantNames <-  c('I', 'II', 'IV', 'III') # Your labels...
    d <- within(d, c <- quadrantNames[(a<0) + (b<0)*2L + 1L])
    head(d) # print data
       a  b   c
    1  1  1   I
    2 -1  1  II
    3 -1 -1 III
    4  1 -1  IV
    

    …and if you want the quadrants mapped differently, just change the order of the labels in quadrantNames.

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

Sidebar

Related Questions

I have a data set that has two tab delimited columns that I plot
I have a GridView that displays data on three columns. On the third column
I have a data frame with two columns, and want to create a third
I have a data set with latitude and longitude coordinates (two separate decimal columns).
I have a data set that should contain 14 columns, but when I read
I have a window that contains a grid with two columns. the first column
I have a simple data set with two columns of data- K and SwStr
I have two columns of data. I'd like to run select statement on them
I have two results from a data set. I want to add both results
I have set up 2 two tables - table userid and table data in

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.