Petr PIKAL/CTCAP napsal dne 10.10.2007 15:03:28:
> r-help-bounces at r-project.org napsal dne 10.10.2007 13:55:32:
>
> > 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 :
> are you sure?
>
> Why 13 in row 5. And using your code my result is
>
> > d
> id x y
> 1 0001 <NA> 21
> 2 0002 <NA> 13
> 3 0003 0001 45
> 4 0004 <NA> 71
> 5 0005 0003 20
> > d$z <- NA
> > rownames(d) <- d$id
> > d$z <- d[d$x,"y"]
> > d
> id x y z
> 0001 0001 <NA> 21 21
> 0002 0002 <NA> 13 21
> 0003 0003 0001 45 13
> 0004 0004 <NA> 71 21
> 0005 0005 0003 20 45
>
> Regards
> Petr
And the reason is that I had <NA> as an extra level in d$x
Petr
>
> >
> >
> > Thanks for your help,
> >
> > Julien
> >
> > --
> > Julien Barnier
> > Groupe de recherche sur la socialisation
> > ENS-LSH - Lyon, France
> >
> > ______________________________________________
> > R-help at 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.