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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:30:10+00:00 2026-06-05T06:30:10+00:00

I have the following type of data ex1 <- data.frame (A = 1:6, B

  • 0

I have the following type of data

ex1 <- data.frame (A = 1:6, B = c(1,2,3,5,1,1), qit = c(1,2,1,2,5,1))
ex1
 A B qit
1 1 1   1
2 2 2   2
3 3 3   1
4 4 5   2
5 5 1   5
6 6 1   1

I tried the following ifelse loop but not geting what I need to ..

 ifelse (ex1[1] == ex1[2] & ex1$qit, 1,
      ifelse ( ex1[1]== ex1$qit || ex1[2]== ex1$qit, 0.5,
           NA))

Condition is:

(1) If A = B = qit , then output 1 (else) 

(2) Either A = qit or B = qit then output = 0.5 (else) 

(3) If none of above conditions hold output NA

I think I have issue with use of &, but I tried ex1[1] == ex1[2] == ex1$qit gives an error.

Expected output:

ex1$out <- c(1, 1, NA, NA, 0.5, 0.5) 
 A B qit out
1 1 1   1 1.0
2 2 2   2 1.0
3 3 3   1  NA
4 4 5   2  NA
5 5 1   5 0.5
6 6 1   1 0.5

Explanation to the solution:

Soultion for the first row:
A = B = qit all conditions hold true so the output 1

For second row 
A = B = qit all conditions hold true so the output 1

For third row 
A = B but not equal to qit  output NA

For fourth row
A is not equal to B nor equal to qit output NA

Fifth row 
A = qit (however A = B = qit doesnot hold true) so output 0.5

Sixth row 
B = qit (however A = B = qit doesnot hold true) so output 0.5
  • 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-05T06:30:12+00:00Added an answer on June 5, 2026 at 6:30 am
    ifelse (ex1[1] == ex1[2] & ex1[1] == ex1$qit, 1,
            ifelse ( ex1[1] == ex1$qit | ex1[2] == ex1$qit, 0.5,
                     NA))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following type of data: mydata <- data.frame (yvar = rnorm(200, 15, 5),
I have following type of data, although data.frame is very large. A1 <- c(A/B,
I have following webservice: [webmethod] public string MakeReservation(?? PassengersInfo)//what data type use for PassengerInfo
I have a table RDCAlerts with the following data in a column of type
I have following exception in the foreach loop Unable to cast object of type
I have following type of data and I want to produce bar graph. Mark
I have the following classes: Defect - represents a type of data that can
I have the following sample xml in a column of xml data type: <diagnostics
I have following type of data, means combination of factors P1 <- c(a, a,
I have the following cell which is used for my custom column data type

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.