apologies on the garbled posting, and thanks for the responses. This was
perfect. Just to close the thread for others, here was my example data set:
a<-c(NA,"China",NA,"Japan",NA,NA)
b<-c("Honduras",NA,"Sudan",NA,"Mexico","Mexico")
dfrm<-cbind(a,b)
David's code was as follows:
dfrm$b[is.na(dfr
Y'all are both absolutely right -- I just skimmed the problem and wrote an
answer all too briefly that both didn't do what was asked and did what it
did instead entirely incorrectly. The syntax suggested by David's email of
7:52 is what I meant to get at...
My apologies for any confusion this caus
On Sep 2, 2011, at 7:51 PM, R. Michael Weylandt wrote:
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"]
One of the rare instances where I disagree wi
On Sep 2, 2011, at 3:51 PM, Josh Tewksbury 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,
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 f
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
-
6 matches
Mail list logo