### Exercise box16.1 12x12 array field<-matrix(1:144,nrow=12,ncol=12,byrow=TRUE) # field rowgroups<-list(c(1:3),c(4:6),c(7:9),c(10:12)) # rowgroups colgroups<-list(c(1:4),c(5:8),c(9:12)) # colgroups toSample<-list(NULL) remember_subplot<-list(NULL) count<-0 for(i in 1:4){ for(j in 1:3){ count<-count+1 submatrix<-field[rowgroups[[i]],colgroups[[j]]] toSample[[count]]<-as.numeric(sample(paste(submatrix),4)) if(count %% 2 != 0) remember_subplot[[count]]<-paste(submatrix) # to be used in the plot }} # toSample ## Make a pretty plot palegrey<-as.numeric(unlist(remember_subplot)) # to differentially colour our subplots, odd versus even plot(NULL,axes=FALSE,xlim=c(0,12),ylim=c(0,12),xlab="",ylab="") a<-0 for(j in 11:0) { for(i in 0:11) { a<-a+1 if(a %in% palegrey) rect(i,j,i+1,j+1,col="grey60") else rect(i,j,i+1,j+1,col="grey20") text(i+.5,j+.5,a) if(a %in% selectcell) text(i+.5,j+.5,a,col="red") }}