[R] Odp: Data manipulation question
Julien Barnier
jbarnier at ens-lsh.fr
Wed Oct 10 13:55:32 CEST 2007
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
More information about the R-help
mailing list