Carson Farmer
2008-Mar-05 17:56 UTC
[R] Replace values in data.frame conditional on another data.frame
Dear List, I am looking for an efficient method for replacing values in a data.frame conditional on the values of a separate data.frame. Here is my scenario: I have a data.frame (A) with say 1000 columns, and 365 rows. Each cell in the data.frame has either valid value, or NA. I have an additional data.frame (B) with the same number of rows and columns, with valid values in all cells. What I would like to do, is replace the cells in B with NA if and only if the corresponding cell in A is NA. I have search extensively for a method to do this, and I'm sure that in the end the solution will be embarrassingly simple, however, any help is greatly appreciated! Cheers, Carson Apologies if this has been posted twice, we are currently experiencing server problems...
John Kane
2008-Mar-05 18:06 UTC
[R] Replace values in data.frame conditional on another data.frame
Try bb[is.na(aa)] <- NA It may be simple but it is not necessarily obvious :) --- Carson Farmer <cfarmer at uvic.ca> wrote:> Dear List, > > I am looking for an efficient method for replacing > values in a > data.frame conditional on the values of a separate > data.frame. Here is > my scenario: > I have a data.frame (A) with say 1000 columns, and > 365 rows. Each cell > in the data.frame has either valid value, or NA. I > have an additional > data.frame (B) with the same number of rows and > columns, with valid > values in all cells. What I would like to do, is > replace the cells in B > with NA if and only if the corresponding cell in A > is NA. > I have search extensively for a method to do this, > and I'm sure that in > the end the solution will be embarrassingly simple, > however, any help is > greatly appreciated! > > Cheers, > > Carson > > Apologies if this has been posted twice, we are > currently experiencing > server problems... > > ______________________________________________ > 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. >