Skip to content

Instantly share code, notes, and snippets.

@SimonGoring
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimonGoring/2220586c4cedaf1f554c to your computer and use it in GitHub Desktop.
Save SimonGoring/2220586c4cedaf1f554c to your computer and use it in GitHub Desktop.
Figure out the age control by year data for Neotoma.
library(neotoma)
library(reshape2)
pollen_data <- get_dataset(datasettype= 'pollen')
full_records <- get_download(pollen_data) # this takes a bit of time
pub.dates <- get_publication(pollen.data) # so does this
earliest.year <- do.call(rbind.data.frame,
lapply(pub.dates, function(x)data.frame(id = NA,
year = min(sapply(x, function(y)y$meta$year)))))
earliest.year$id <- sapply(pollen.data, function(x) x$dataset$dataset.meta$dataset.id)
aa <- lapply(full_records, function(x){
control.table <- try(get_chroncontrol(x$sample.meta$chronology.id[1])$chron.control$control.type)
if(!class(control.table) == 'try-error'){
output <- data.frame(control = as.character(control.table), id = x$dataset$dataset.meta$dataset.id)
} else {
output <- data.frame(control = NA, id = NA)
}
output})
chron.table <- do.call(rbind.data.frame, aa)
chron.table$year <- earliest.year$year[match(chron.table$id, earliest.year$id)]
model.table <- dcast(chron.table, formula = control~year, length)
@Maarten14C
Copy link

Thanks, Simon.
However at lines 12-19 I get lots of 'Error in get_chroncontrol(x$sample.meta$chronology.id[1]) :
chronologyid must be numeric.'
Trying to work around this.

@SimonGoring
Copy link
Author

It's because it should be pulling from full_data, not the pollen_data that's getting pulled. That's my mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment