##load the data
data(mesa.data.model)
##create a matrix with the CV-schemes
I.cv <- createCV(mesa.data.model, groups=10)
##number of observations in each CV-group
colSums(I.cv)
##Which sites belong to which groups?
ID.cv <- lapply(apply(I.cv,2,list),function(x)
unique(mesa.data.model$obs$ID[x[[1]]]))
print(ID.cv)
##Note that the sites with distance 0.084<min.dist
##are grouped together (in group 10).
mesa.data.model$dist[ID.cv[[10]],ID.cv[[10]]]
##Find out which location belongs to which cv group
I.col <- apply(sapply(ID.cv,function(x) mesa.data.model$location$ID
%in% x), 1, function(x) if(sum(x)==1) which(x) else 0)
names(I.col) <- mesa.data.model$location$ID
print(I.col)
##Plot the locations, colour coded by CV-grouping
plot(mesa.data.model$location$long, mesa.data.model$location$lat,
pch=23+floor(I.col/max(I.col)+.5), bg=I.col,
xlab="Longitude",ylab="Latitude")
Run the code above in your browser using DataLab