Skip to content
Prev 306248 / 398506 Next

Script to count unique values from two linked matricies

Hi Ben,

No problem.

The code could be collapsed to 2 steps:
library(data.table)
library(reshape)
datm<-merge(melt(dat1),melt(dat2),by="Species")
dat3<-data.frame(unlist(lapply(lapply(split(datm,datm$variable.x),function(x) data.table(x[!is.na(x$value.x),])),function(x) sum(x[,list(length(unique(value.y))),list(variable.y)]$V1))))
?colnames(dat3)<-"Trait_Richness"
dat3
#????? Trait_Richness
#Site1????????????? 5
#Site2????????????? 7
#Site3????????????? 3
A.K.




----- Original Message -----
From: Benjamin Gillespie <gybrg at leeds.ac.uk>
To: arun <smartpink111 at yahoo.com>
Cc: PIKAL Petr <petr.pikal at precheza.cz>; Rui Barradas <ruipbarradas at sapo.pt>; Heramb Gadgil <heramb.gadgil at gmail.com>; R help <r-help at r-project.org>
Sent: Tuesday, September 25, 2012 9:34 AM
Subject: RE: [R] Script to count unique values from two linked matricies

Excellent - thanks so much.

Ben Gillespie
Research Postgraduate

School of Geography
University of Leeds
Leeds
LS2 9JT

Tel: +44(0)113 34 33345
Mob: +44(0)770 868 7641
http://www.geog.leeds.ac.uk/