1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| library(stringr)
nindividual <-88325
tag <-paste("BTM", str_pad(1:nindividual, 6, pad ="0"), sep ="")
plot20_x <- str_pad(1:20, 2, pad ="0") plot20_y <- str_pad(1:25, 2, pad ="0") names_temp <- expand.grid(plot20_x, plot20_y) plot20_names <-paste(names_temp[,1],names_temp[,2], sep ="") survey_plot20_names <-sample(plot20_names,nindividual, replace=TRUE)
g5x <-round(runif(nindividual)*5, 2) g5y <-round(runif(nindividual)*5, 2)
subplot5 <-sample(1:16, nindividual, replace=TRUE)
dbh <-round(rexp(nindividual,rate =2)*50+1, 1)
btmdat <- data.frame(tag, survey_plot20_names, subplot5, g5x, g5y, dbh)
btmdat <- btmdat[order(btmdat$survey_plot20_names, btmdat$subplot5),]
btmdat$location5x <-rep(NA, nrow(btmdat)) btmdat$location5y <-rep(NA, nrow(btmdat))
btmdat$location5x[btmdat$subplot5 ==1]<-1 btmdat$location5x[btmdat$subplot5 ==2]<-2 btmdat$location5x[btmdat$subplot5 ==3]<-3 btmdat$location5x[btmdat$subplot5 ==4]<-4 btmdat$location5x[btmdat$subplot5 ==5]<-4 btmdat$location5x[btmdat$subplot5 ==6]<-3 btmdat$location5x[btmdat$subplot5 ==7]<-2 btmdat$location5x[btmdat$subplot5 ==8]<-1 btmdat$location5x[btmdat$subplot5 ==9]<-1 btmdat$location5x[btmdat$subplot5 ==10]<-2 btmdat$location5x[btmdat$subplot5 ==11]<-3 btmdat$location5x[btmdat$subplot5 ==12]<-4 btmdat$location5x[btmdat$subplot5 ==13]<-4 btmdat$location5x[btmdat$subplot5 ==14]<-3 btmdat$location5x[btmdat$subplot5 ==15]<-2 btmdat$location5x[btmdat$subplot5 ==16]<-1
btmdat$location5y[btmdat$subplot5 ==1]<-1 btmdat$location5y[btmdat$subplot5 ==2]<-1 btmdat$location5y[btmdat$subplot5 ==3]<-1 btmdat$location5y[btmdat$subplot5 ==4]<-1 btmdat$location5y[btmdat$subplot5 ==5]<-2 btmdat$location5y[btmdat$subplot5 ==6]<-2 btmdat$location5y[btmdat$subplot5 ==7]<-2 btmdat$location5y[btmdat$subplot5 ==8]<-2 btmdat$location5y[btmdat$subplot5 ==9]<-3 btmdat$location5y[btmdat$subplot5 ==10]<-3 btmdat$location5y[btmdat$subplot5 ==11]<-3 btmdat$location5y[btmdat$subplot5 ==12]<-3 btmdat$location5y[btmdat$subplot5 ==13]<-4 btmdat$location5y[btmdat$subplot5 ==14]<-4 btmdat$location5y[btmdat$subplot5 ==15]<-4 btmdat$location5y[btmdat$subplot5 ==16]<-4
btmdat$survey_plot20_names <- as.character(str_pad(btmdat$survey_plot20_names, 4, pad ="0"))
x20 <-substr(btmdat$survey_plot20_names,start=1, stop=2)
y20 <-substr(btmdat$survey_plot20_names,start=3, stop=4)
btmdat$gx <- g5x +(btmdat$location5x -1)*5+(as.numeric(x20)-1)*20 btmdat$gy <- g5y +(btmdat$location5y -1)*5+(as.numeric(y20)-1)*20
final_btmdat <-subset(btmdat, select =!colnames(btmdat)%in%c("location5x", "location5y")) head(final_btmdat) summary(final_btmdat)
|