Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing two columns in a data frame across many rows

Tags:

People also ask

How do I compare two columns for differences in R?

We can compare two columns in R by using ifelse(). This statement is used to check the condition given and return the data accordingly.

How do you compare values in two data frames?

The compare method in pandas shows the differences between two DataFrames. It compares two data frames, row-wise and column-wise, and presents the differences side by side. The compare method can only compare DataFrames of the same shape, with exact dimensions and identical row and column labels.


I have a data frame that I'm working with in which I'd like to compare a data point Genotype with two references S288C and SK1. This comparison will be done across many rows (100+) of the data frame. Here are the first few lines of my data frame:

    Assay   Genotype S288C SK1
1   CCT6-002     G     A    G
2   CCT6-007     G     A    G
3   CCT6-013     C     T    C
4   CCT6-015     G     A    G
5   CCT6-016     G     G    T

As a final product, I'd like a character string of 1's (S288C) and 0's (SK1) depending on which of the references the data point matches. Thus in the example above I'd like an output of 00001 since all except the last match SK1.