Patrick Zimmermann
2007-Sep-11 08:01 UTC
[R] composition of a matrix by matches between two data frames
Dear R-users, I want to compose a new table (a presence/absence matrix of species in regions) by matches between two data frames. The first data frame has the species as header and the habitats in which they occure as elements. The second data frame has the regions as header and the occuring habitats as elements. To fill a cell in the new matrix (e.g. spcs.x in region.y) I want R to compare the habitat lists of spcs.x and region.y. If any of the habitats occurs in both lists the value of the cell shall be 1. The structure I used looks like this: for(i in 1:ncol(matrix)) matrix[match(species[,i], region[,i]), i]<- 1 It returns a result, but it contains only complete and not the desired partial matches. I have no clue how change this. Thanks in advance for your suggestions, Patrick