Home > other >  Comparing Character Variables
Comparing Character Variables

Time:01-24

I would like to compare two different character variables in R Studio. The first column (BZ_Pred) shows what participants predicted to be their 5 most used Apps. The second column (BZ_Act) shows the 5 Apps that were actually used the most.

My Dataset

Now I would like to create a third column that contains a "Yes" if the 1st App was guessed correctly and a "No" if the 1st App wasn't guessed correctly.

But how can I compare those App names to another?

Thanks in advance!

I tried if() and else(), but it didn't work.

CodePudding user response:

You may simply use the logical equality operator == along with the ifelse() function here:

df$eq <- ifelse(df$BZ_Pred == df$BZ_Act, "Yes", "No")
  • Related