r - create binary matrix from data.frame -


how can create binary matrix data.frame 2 columns first column represents e.g. species , other region? data.frame in tall format seen below

species region species1 1 species1 2 species1 3 species2 2 species2 4 species2 5 species2 6 species3 1 species3 2 species4 5 species5 3 species5 4 

and matrix have unique species rows , unique regions columns. matrix filled 1s species present , 0s species absent, below

         1  2  3  4  5  6 species1 1  1  1  0  0  0 species2 0  1  0  1  1  1 species3 1  1  0  0  0  0 species4 0  0  0  0  1  0 species5 0  0  1  1  0  0 

any pointers appreciated, thanks!

you looking function table documentation here

if data.frame df, have do

table(df) 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -