# Example of using the Reshape package to make encounter histories for RMark #Note: this only works if you capture at least one individual per trapping session. If you didn't, add a blank row to the data set for each session in which you did not catch an individual. An alternative approach to using Reshape is to create a dummy (null) list of all possible capture dates and then merge with your data. #Be sure to install the Reshape package! #Make fake banding data that have a single row for each capture per individual bn<-c("1","1","2","3","3","3","4","5","6","6","7","8","9") #fake band numbers season<-c(1,2,3,1,2,3,1,4,3,4,1,1,1) #fake seasons recapture<-c(1,1,1,1,1,1,1,1,1,1,1,1,1) #extra column needed for data organization bd<-data.frame(bn=bn, season=season, recapture=recapture) #banding data #Reshape data from rows to table library("reshape") bdm=melt(bd, id = c("bn", "season"), measured = c("recapture")) # melt data bdc=cast(bdm, bn ~ season, min) #casts the molten data into a new form. could use min, max, or ave, since all are 1s. bdc #replace Inf with 0. bdc=as.matrix(bdc) #matrix format is needed to remove Infs, but removes column "bn" for some reason(?). head(bdc) bdc[which(bdc==Inf)]<-0 bdc=as.data.frame(bdc) #adds column "bn" back in. colnames(bdc)=c("Al.band", "S1", "S2", "S3", "S4") #Add 'S' so that column names are not numeric, which is important for RMark head(bdc) bdc$ch=paste(bdc$S1, bdc$S2, bdc$S3, bdc$S4, sep='') #concatenate into new capture history (ch) column bdc=subset(bdc, select = -c(2, 3, 4, 5)) #remove extra columns #From here, you can merge() with covariates for each bird by using band number. Before importing to RMark, you need to remove the band numbers. chdata<-bdc[,-1] chdata str(chdata)