forked from rmbranto/FRB_MS883_MacLellanSprague
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetData2.R
73 lines (55 loc) · 1.63 KB
/
getData2.R
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
# RMBranton Feb 2016
# process Maclellan_Sprague(1966) data
#install.packages("XLConnect")
library(XLConnect)
#install.packages("plyr")
library(plyr)
source('functions2.r')
get.wz<-function(
worksheet,
data.sheets=c(1:8,10),
data.transpose=TRUE,
data.exclude.totals=TRUE,
data.num.ids=4,
data.var.name='spnumber',
sta.sheets=c(12,13),
sta.transpose=TRUE,
sta.date.format='%d-%m-%Y'){
wb<-loadWorkbook(worksheet)
# get sation data
cat('\n getting stations data from tables ...\n')
lz.sta<-NULL
for (sheet.name in getSheets(wb)[sta.sheets]){
lz.sta<-rbind(lz.sta,get.sta.lz(wb,sheet.name,sta.transpose,sta.date.format))
}
# merge station data with location metadata
lz.sta<-
merge(
x=lz.sta,
y=readWorksheet(wb,sheet='Locations',header=T)[,c(2,3,4,5,12,15,16,17)],
by='station')
# get sample data
cat('\n getting samples data from tables ...\n')
lz.data<-NULL
for (sheet.name in getSheets(wb)[data.sheets]){
lz.data<-rbind(lz.data,get.data.lz(wb,sheet.name,data.transpose,data.exclude.totals,data.num.ids,data.var.name))
}
# merge station data with sample data
wz<-merge(
x=lz.sta,
y=dcast(lz.data,year+station+sample+spnumber~observation,fun.aggregate=sum),
by=c('year','station','sample')
)
# get taxa list and merge with sampling data
taxa<-readWorksheet(wb,sheet='WoRMS_Matched',header=T)
taxa$spnumber<-gsub('*','',taxa$spnumber,fixed=T)
wz<-merge(x=wz,y=taxa,by='spnumber')
source('metadata.r')
wz<-merge(x=metadata,y=wz)
#lz.final$WoRMSLink<-
# paste("http://www.marinespecies.org/aphia.php?p=taxdetails&id=",
# lz.final$AphiaID_accepted,
# sep='')
source('write.ipt.R')
extents()
}