date() #s <- read.delim("Hobson:Users:wag:Archive:Active:Ecophenetics and Comp. Index:CI Database:PRINCE2002.unsort.TAB.txt", header = FALSE) s <- read.delim('/Users/wag/Archive/Active/CITrends/AJSMS/data/PRINCE2002.unsort.TAB.txt', header = FALSE) dim (s) names (s) <- c('CLASSNUM', 'FAMILY', 'GENUS', 'SPECIES', 'AUTHOR', 'STATUS', 'REFNO', 'AGE', 'FORMATION', 'MEMBER', 'LOCALITY', 'REMARKS') #for (i in 1:12){ # s[,i] <- as.character (s[,i]) #} # Make variable CIC CIC <- substr(as.character(s[,1]), 1, 3) s <- cbind (s, CIC) rm(CIC) # Make variable AGECODE AGECODE <- substr(as.character(s[,1]), 4, 4) s <- cbind (s, AGECODE) rm(AGECODE) # Scrag bad records CORRUPT <- rep (0, nrow (s)) CORRUPT[1897] <- 1 s <- cbind (s, CORRUPT) rm(CORRUPT) # Split CI by formation fm.names <- as.character(unique(s[!s$CORRUPT,]$FORMATION)) CICs.angio.t <- c('t', 'e', NA, NA, NA, NA, 't', 'e', 't', 't', 't', 'e', NA, 't', 't', 't', 'e', 'e', 'e', 'e', NA, 't', 'e', NA, 't', 'e', 't', 'e', NA, 't', 'e', 't', 'e', NA, 't', 'e', 't', 'e', NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 't', 'e', NA, NA, 't', 'e', 't', 'e') CICs.angio.t[is.na(CICs.angio.t)] <- '?' spectra <- vector (length = length(fm.names), mode = 'list') age <- rep ('', length(fm.names)) age.code <- rep ('', length(fm.names)) n <- rep (0, length(fm.names)) a <- rep (0, length(fm.names)) P <- rep (0, length(fm.names)) #unique (s[!s$CORRUPT,]$FORMATION) #for (i in 1:5){ for (i in 1:length(fm.names)){ fm.frame <- s[as.character(s$FORMATION) == fm.names[i], ] #cat(dim(fm.frame), '\n') age[i] <- as.character(fm.frame$AGE[1]) age.code[i] <- as.character(fm.frame$AGECODE[1]) spectra[[i]] <- table (fm.frame$CIC) n[i] <- as.numeric(sum(table(fm.frame$CIC))) a[i] <- as.numeric(sum(table(fm.frame$CIC)[1:63])) P[i] <- as.numeric(sum(table(fm.frame$CIC)[CICs.angio.t == 'e'])) / as.numeric((sum(table(fm.frame$CIC)[CICs.angio.t == 'e']) + sum(table(fm.frame$CIC)[CICs.angio.t == 't']))) } PsThroughTime <- data.frame (I(fm.names), I(age), I(age.code), I(n), I(a), I(P)) #row.names(PsThroughTime) <- fm.names #names(PsThroughTime) <- c('fm.names','age', 'n', 'a', 'P') #PsThroughTime$age <- as.character(PsThroughTime$age) #PsThroughTime$n <- as.numeric(PsThroughTime$n) #PsThroughTime$a <- as.numeric(PsThroughTime$a) #PsThroughTime$P <- as.numeric(PsThroughTime$P) #gtmin <- as.numeric(PsThroughTime$a > 20) #PsThroughTime <- cbind(PsThroughTime, gtmin) PsThroughTime.ngt20 <- PsThroughTime[PsThroughTime$a > 20, ] PsThroughTime.ngt20 <- PsThroughTime.ngt20[order (PsThroughTime.ngt20$age.code, PsThroughTime.ngt20$fm.names), ] summary(split(PsThroughTime$fm.names, PsThroughTime$age.code)) #pdf() age.splits <- split (PsThroughTime.ngt20$P, PsThroughTime.ngt20$age.code) b <- boxplot(age.splits, varwidth = TRUE, xaxt = 'n', ylab = 'Percentage Entire (P)', main = 'Leaf Margins of 60 floras in Compendium Index') for (i in 1:length(age.splits)){ points (rep (i, length(age.splits[[i]])), age.splits[[i]], col = 'blue') } axis (1, labels = c("plio", "mio", "oligo", "eo", "paleo", "maas", "camp", "sant", "ceno", "alb", "apt"), at = 11:1) lines (b$stats[3,], col = 'red') mtext (at = 1:11, text = paste ('n=', b$n, sep = ''), side = 1, line = 3) for (i in 1:length(age.splits)){ text (rep (i, length(age.splits[[i]])), age.splits[[i]], labels = split(PsThroughTime.ngt20, PsThroughTime.ngt20$age.code)[[i]]$fm.names, cex = 0.5) } rm (b, age.splits, i) #dev.off() # Run overnight date() CICs <- c(100:155, 160:164, 170:172, 180:186, 190, 200, 210:220, 230:238, 240, 300, 350, 400, 500:509, 600, 700, 710, 800, 900, 910, 920, 930, 940, 950, 990) spectra.frame <- data.frame(matrix(0, nrow = length(fm.names), ncol = 118)) names(spectra.frame) <- CICs row.names(spectra.frame) <- fm.names for(i in 1:length(fm.names)){ for(j in CICs){ foo <- as.numeric(spectra[[i]][(names(spectra[[i]]) == paste (j))]) if (length (foo) != 0){ spectra.frame[i, names(spectra.frame) == paste(j)] <- foo } } } date() write.table(spectra.frame, file = 'CIFm.spectra.txt') spectra.frame.ngt20 <- spectra.frame[rowSums(spectra.frame[,1:56]) > 20,1:56] rm (a, n, age, P, gtmin, age.code, s, fm.frame, fm.names)