Hi Petr, > d$z<-NA > d$z[d$x %in% d$id] <- d$y[d$id %in% d$x] > > works in this particular case but it means you do not have multiple same > ids and X
Thanks for the idea. But the problem is that I can have multiple ids... In fact in the meantime I found a solution by using row names : R> d id x y 1 0001 <NA> 21 2 0002 <NA> 13 3 0003 0001 45 4 0004 <NA> 71 5 0005 0003 20 R> rownames(d) <- d$id R> d$z <- NA R> d$z <- d[d$x,"y"] R> d id x y z 0001 0001 <NA> 21 NA 0002 0002 <NA> 13 NA 0003 0003 0001 45 21 0004 0004 <NA> 71 NA 0005 0005 0003 20 13 Thanks for your help, Julien -- Julien Barnier Groupe de recherche sur la socialisation ENS-LSH - Lyon, France ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.