locations Data Frame (by longitude/latitude and station)
station_ids <- sort(unique(data[, 1])) #station ids
locations <- matrix(NA, #create empty matrix
nrow = length(station_ids),
ncol = 2)
locations <- as.data.frame(locations) #matrix to data frame
row.names(locations) <- station_ids #assigning station ids to empty locations data frame
names(locations) <- c("lat", "lon") #assigning lat and lon names to empty locations data frame
for (j in 1:length(station_ids)){ #loop goes through all 36 stations
station_ind = data[, 1] == station_ids[j] #row is True for station i and False if not
latitude_longitude <- unique(data
[station_ind, 4:5]) #latitude and longitude repectively
locations[j, ] <- latitude_longitude #updating/adding lat and lon to locations data
}
write.csv(locations, "~/Desktop/ENSO/Data_Frames/locations.csv")