data<-read.table(file="PNG_transects.txt",header=TRUE) head(data) tail(data) PA<-replace(PA<-data,PA>1,1) species_recorded <- NULL hold_temp<-NULL for (i in 1:ncol(PA)){ temp<- grep(1,PA[,i]) hold_temp<-c(hold_temp,temp) species_recorded<-c(species_recorded,length(unique(hold_temp))) } plot(species_recorded, xlab= "Transect number", ylab="Total number of species") N<-100 M<- matrix(NA,nrow=N, ncol=ncol(PA)) # to hold the results of N (100) random sequences for (i in 1:N){ to_add_seq<-sample (1:50, 50, replace=FALSE) species_recorded <- NULL hold_temp<-NULL for (j in to_add_seq){ temp<- grep(1,PA[,j]) hold_temp<-c(hold_temp,temp) species_recorded<-c(species_recorded,length(unique(hold_temp))) } M[i,]<- species_recorded } head(M) plot(NULL, xlim=c(1,50),ylim=c(1,93), xlab= "Transect number", ylab="Total number of species") for (i in 1:100){ points(c(1:50),M[i,],pch= 15,cex=0.2)} points(c(1:50),colMeans(M), col="red", pch=16) lines(smooth.spline(c(1:50),colMeans(M), spar=0.4, all.knots=F), lwd=2, lty=1,col="blue")