Your data frame didn't come across legibly, try sending it in plain text
using the dput() command.

That said, I'd guess you want something like this:

d[is.na(d$a),"a"] <- d[is.na(d$b),"b"]

The idea is that is.na(d$a) selects only those rows where column "a" is NA
and then moves b values into a for only those rows.

Write back with the dput() data frame if this doesn't work.

Hope this helps,

Michael Weylandt

On Fri, Sep 2, 2011 at 3:51 PM, Josh Tewksbury <tewk...@uw.edu> wrote:

> Hello, I have a dataframe that looks like this:
>
>  a b  NA Honduras  China NA  NA Sudan  Japan NA  NA Mexico  NA Mexico
> I would like to replace the NA values in column b with the non-NA values in
> column a.  I have tried a number of techniques, (if, ifelse) but I must
> have
> the logic wrong.
>
> Thanks
> --
> Josh
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to