I have two datasets with latitude, longitude and temperature data. One dataset corresponds to a geographic area of ​​interest, with corresponding lat / long pairs that form the border and contents of the area (Matrix dimension = 4518x2)
Another dataset contains lat / long and temperature data for a larger area that covers the area of ​​interest (Matrix Dimenion = 10875x3).
My question is: how do you extract the corresponding row data (lat, long, temperature) from the second dataset that corresponds to the first lat / long dataset?
I tried many “for loops”, “subset” and “unique” commands, but I can’t get the corresponding temperature data.
Thanks in advance!
10/31 Editing: I forgot to mention that I use "R" to process this data.
The lat / long data for the area of ​​interest was presented as a list of 4518 files containing the lat / long coordinates in the name of each file:
x<- dir() lenx<- length(x) g <- strsplit(x, "_") coord1 <- matrix(NA,nrow=lenx, ncol=1) coord2 <- matrix(NA,nrow=lenx, ncol=1) for(i in 1:lenx) { coord1[i,1] <- unlist(g)[2+3*(i-1)] coord2[i,1] <- unlist(g)[3+3*(i-1)] } coord1<-as.numeric(coord1) coord2<-as.numeric(coord2) coord<- cbind(coord1, coord2)
The lat / long and temperature data were obtained from the NCDF file with temperature data for 10,875 pairs of lat / lengths:
long<- tempcd$var[["Temp"]]$size[1] lat<- tempcd$var[["Temp"]]$size[2] time<- tempcd$var[["Temp"]]$size[3] proj<- tempcd$var[["Temp"]]$size[4] temp<- matrix(NA, nrow=lat*long, ncol = time) lat_c<- matrix(NA, nrow=lat*long, ncol=1) long_c<- matrix(NA, nrow=lat*long, ncol =1) counter<- 1 for(i in 1:lat){ for(j in 1:long){ temp[counter,]<-get.var.ncdf(precipcd, varid= "Prcp", count = c(1,1,time,1), start=c(j,i,1,1)) counter<- counter+1 } } temp_gcm <- cbind(lat_c, long_c, temp)`
So now the question is how to remove the values ​​from "temp_gcm" that correspond to the lat / long data pairs from "coord?"