# Script to assign a depth to each lionfish record library('raster') # bathymetic data map <- raster(x="Bathymetry data.asc") # GPS locations of lionfish df1 <- read.csv(“ESM1.csv", header=T) df1$LatDD <- as.numeric(as.character(df1$LatDD)) df1$LongDD <- as.numeric(as.character(df1$LongDD)) df1$depth <- NA # removing null records df1 <- df1[is.na(df1$LongDD)==FALSE, ] # Looping through for(i in (1000 : nrow(df1))) { print(i) temp <- data.frame(df1$LongDD[i], df1$LatDD[i]) depth <- extract(map, temp) df1$depth[i] <- depth } write.csv(df1, "lionfish_depth_allocation.csv")