Starting with your data
In[]:=
data={{"Species","Color1","Color2","Color3","Color4"},{"species B","black","red","blue","pink"},{"species A","yellow","black","white","orange"},{"species c","red","indigo","cream","yellow"}};
Let’s put some structure on the data
In[]:=
colorsBySpecies=Association[Through[Rule[First,Rest][#]]&/@Rest@data]
Out[]=
species B{black,red,blue,pink},species A{yellow,black,white,orange},species c{red,indigo,cream,yellow}
And let’s extract the unique colors
In[]:=
uniqueColors=Union@@Values@colorsBySpecies
Out[]=
{black,blue,cream,indigo,orange,pink,red,white,yellow}
Let’s create a helper function that makes a row of data where 1s are inserted where colors match.
In[]:=
makeRow[allColors_][colors_]:=SparseArray[Thread[Position[allColors,Alternatives@@colors]->1],{Length@allColors}]
We can test it
In[]:=
makeRow[uniqueColors][colorsBySpecies["species A"]]//Normal
Out[]=
{1,0,0,0,1,0,0,1,1}
Now, we’re going to map our function over our structured data, and then we’re going to combine the species name with the data, so we have named rows
In[]:=
namedRows=KeyValueMap[Flatten@*List,makeRow[uniqueColors]/@colorsBySpecies]
Out[]=
{{species B,1,1,0,0,0,1,1,0,0},{species A,1,0,0,0,1,0,0,1,1},{species c,0,0,1,1,0,0,1,0,1}}
Then we add the column headers
In[]:=
headedTable=Prepend[namedRows,Prepend[uniqueColors,data[[1,1]]]]
Out[]=
{{Species,black,blue,cream,indigo,orange,pink,red,white,yellow},{species B,1,1,0,0,0,1,1,0,0},{species A,1,0,0,0,1,0,0,1,1},{species c,0,0,1,1,0,0,1,0,1}}
In[]:=
TableForm[headedTable]
Out[]//TableForm=
Species | black | blue | cream | indigo | orange | pink | red | white | yellow |
species B | 1 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 |
species A | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 |
species c | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 |
Having done all of that, I’m wondering where you’re going next, because this structure might not really be the best for further processing. You might want to look into using Dataset or Association.