Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Comparing Character Variables in R

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But how can I compare those App names to another?

Thanks in advance!

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

>Solution :

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")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading