y=function(station,lat,lon){
temp=cbind(station,lat,lon)
lat_ind=lat!="unknown"
lon_ind=lon!="unknown"
if(all(lat_ind)==0){
hash=unique(temp[lat_ind,])
ind2=hash[,1]==station[!lat_ind]
temp[!lat_ind,]=temp[ind2,]
return(temp)
}else if(all(lon_ind)==0){
hash=unique(temp[lon_ind,])
ind2=hash[,1]==station[!lon_ind]
temp[!lon_ind,]=temp[ind2,]
return(temp)
}else {
return(temp)
}
}
##case1
station <- c("a","b","c","c","c")
lat <- c("1","2","3","3","unknown")
lon <- c("6","7","8","8","unknown")
y(station,lat,lon)
# station lat lon
# [1,] "a" "1" "6"
# [2,] "b" "2" "7"
# [3,] "c" "3" "8"
# [4,] "c" "3" "8"
# [5,] "c" "3" "8"
##case2
station <- c("a","b","c","c","c")
lat <- c("1","2","3","3","3")
lon <- c("6","7","8","8","unknown")
y(station,lat,lon)
# station lat lon
# [1,] "a" "1" "6"
# [2,] "b" "2" "7"
# [3,] "c" "3" "8"
# [4,] "c" "3" "8"
# [5,] "c" "3" "8"
##case3
station <- c("a","b","c","c","c")
lat <- c("1","2","3","3","unknown")
lon <- c("6","7","8","8","8")
y(station,lat,lon)
# station lat lon
# [1,] "a" "1" "6"
# [2,] "b" "2" "7"
# [3,] "c" "3" "8"
# [4,] "c" "3" "8"
# [5,] "c" "3" "8"