PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 8, 2022

[FIXED] How to compare two columns in a dataframe with opposite values

 October 08, 2022     data-cleaning, data-visualization, r, statistics     No comments   

Issue

In a data frame, I would like to compare two columns that have opposite values, is there a way to check or even visualize it?

Col1 | Col2
------------
  T  |   F 
  F  |   T 
  T  |   F 
  T  |   F 

Solution

Something like this?

Update: See @akrun's comment:

df %>% mutate(isOpposite = Col1 == Col2)
df %>% 
  mutate(isOpposite = ifelse(Col1 == Col2, TRUE, FALSE))
   Col1  Col2 isOpposite
1  TRUE FALSE      FALSE
2 FALSE  TRUE      FALSE
3  TRUE FALSE      FALSE
4  TRUE FALSE      FALSE


Answered By - TarJae
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing