-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateCSVbySP.R
47 lines (40 loc) · 1.67 KB
/
generateCSVbySP.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
#Creates CSV files of occurrences for each species with a model (.RData)
#Load .RData objects with occurrences and geographical/taxonomic validation
load("C:/Users/jorge.velasquez/Google Drive/Bases/Ocurrencias/CO_GBIFSIB_23082013.RData")
load("C:/Users/jorge.velasquez/Google Drive/Bases/Ocurrencias/GEO_GBIFSIB_23082013.RData")
load("C:/Users/jorge.velasquez/Google Drive/Bases/Ocurrencias/GBIFSIB_23082013.RData")
df<-data.frame(id=paste0(db$db$collection,"-",db$db$catalogNumber),
species=cofTable2$Nombre,
speciesOriginal=db$db$species,
x=db$db$lon,
y=db$db$lat,
locality=db$db$locality,
adm2=db$db$adm2,
adm1=db$db$adm1,
alt=db$db$alt,
earliestDateCollected=db$db$earliestDateCollected,
institution=db$db$institution,
collector=db$db$collector,
basisOfRecordd=db$db$basisOfRecord)
#Seleccione registros con el departamento bien
rem=which(set16$bien_depto==1)
df<-df[rem,]
#Quitar duplicados basados en los campos species, lat, lon
sub.df<-df[,c("species","x","y")]
idx<-duplicated(sub.df)
df<-df[!idx,]
#Create CSV
files<-list.files("W:/Modelos/20131122",pattern="*.RData$")
spNames<-sapply(strsplit(files,"\\."),"[[",1)
spNames2<-paste(sapply(strsplit(spNames,"_"),"[[",1),sapply(strsplit(spNames,"_"),"[[",2))
for (i in 1:length(spNames)){
idx=which(df$species%in%spNames2[i])
if(length(idx)==0){
print(paste("model not available for ",spNames2[i]))
next
} else {
print(spNames2[i])
out.df<-df[idx,]
write.csv(out.df,paste0("W:/Visor/20131122/CSV/",spNames[i],".csv"),row.names=F)
}
}