Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

How do I make a binary matrix comparing several columns

$
0
0

I'm new to programming and R.

I have a data like this in columns:

C1        C2     C3        C4          C5
Apple            Apple     Banana      Banana
Banana           Orange    Orange
Orange

I want to make a binary matrix comparing all the columns to C1 where 1 is TRUE and 0 is FALSE. I want something like this:

 C1        C2     C3        C4          C5
Apple      0      1         0           0
Banana     0      0         1           1
Orange     0      1         1           0

Does anyone know how to do this? Thank you.


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>