I have
    idx <- c(1397, 2000, 3409, 3415, 4077, 4445, 5021, 5155) 
    idy <- c( 1397, 2000, 2860, 3029, 3415, 3707, 4077, 4445, 5021, 5155, 
             5251, 5560)
   agex <- c(NA, NA, NA, 35, NA, 62, 35, 46)
   agey <- c( 3, 45,  0, 89,  7,  2, 13, 24, 58,  8,  3, 45)
   dat1 <- as.data.frame(cbind(idx, agex))
   dat2 <- as.data.frame(cbind(idy, agey))
Now I want whenever agex = NA, and idx = idy, that agey = NA, so that
       idy agey
  1    1397   NA
  2    2000   NA
  3    2860    0
  4    3029   89
  5    3415    7
  6    3707    2
  7    4077   NA
  8    4445   24
  9    5021   58
  10   5155    8
  11   5251    3
  12   5560   45
I have tried this
ifelse(is.na(dat1$agex) | dat1$idx %in% dat2$idy, NA, dat2$agey)
it returns NAs at the correct indices, but shortens idy to the length of idx.
 
    