R/RIind.r

Defines functions RIind

Documented in RIind

RIind<-function(dd,pop,ind){
fls=as.factor(paste(pop,'-',ind))
pop=as.factor(pop)
m=length(colnames(dd))
#
bij=tapply(dd[,1],fls,length)
flowernum=aggregate(dd[,1],list(pop,fls),"length")
colnames(flowernum)=c("pop","fls","flowernum")
a=length(levels(fls))
b=tapply(fls,pop,length)
flsdd=array(0,dim=c(m,a))
colnames(flsdd)=levels(fls)
rownames(flsdd)=colnames(dd)
for (i in 1:m){
flsdd[i,]=tapply(dd[,i],fls,sum)
}
flsdd2=t(flsdd)
popfls=unique(data.frame(pop,fls))
popflsdd=cbind(popfls,flsdd2)
aij=popflsdd
LL=levels(aij$pop)
TD=as.matrix(bij)
m2=length(aij)
xij=aij[,3:m2]/TD
X=cbind(aij[,1:2],xij)
R0=rowSums(X[,3:ncol(X)])
R1=X[,1:2]
R=cbind(R1,as.matrix(R0))
rownames(R)=c(1:nrow(aij))
colnames(R)=c("population","individual","r")
R.max=tapply(R$r,R$population,max)
R.min=tapply(R$r,R$population,min)
R.mean=tapply(R$r,R$population,mean)
R.sd=tapply(R$r,R$population,sd)
R.length=tapply(R$r,R$population,length)
Result=t(rbind(R.length,R.min,R.max,R.mean,R.sd))
print(round(Result,2))
list(res=Result,NO.of.ind=a,aij=aij,bij=TD,xij=X,R=R)
}

Try the flower package in your browser

Any scripts or data that you put into this service are public.

flower documentation built on May 1, 2019, 9:27 p.m.