Hi all, I think this is a very basic question, but I'm new to this so please bear with me. I'm using match to translate elements of a data frame using a lookup table. If the content of a particular cell is not found in the lookup table, the function returns NA. I'm wondering how I can just ignore those cells, and return the original contents if no match is found in the lookup table. Many thanks in advance, this site has been extremely helpful for me so far, Jill Jill Hollenbach, PhD, MPH Assistant Staff Scientist Center for Genetics Children's Hospital Oakland Research Institute jhollenbach at chori.org -- View this message in context: http://www.nabble.com/how-to-have-%27match%27-ignore-no-matches-tp25756601p25756601.html Sent from the R help mailing list archive at Nabble.com.
On Oct 5, 2009, at 4:01 PM, Jill Hollenbach wrote:> > Hi all, > I think this is a very basic question, but I'm new to this so please > bear > with me. > > I'm using match to translate elements of a data frame using a lookup > table. > If the content of a particular cell is not found in the lookup > table, the > function returns NA. I'm wondering how I can just ignore those > cells, and > return the original contents if no match is found in the lookup table.Can you construct a simple example (with sufficient complexity and lack of matches) that can be cut-and-pasted into the console along with specification of how you want your results? I cannot understand what you are asking for a "translat[ion] of a dataframe" and when you request the "return [of] the original contents if no match is found in the lookup table." -- David Winsemius, MD Heritage Laboratories West Hartford, CT
On 6/10/2009, at 9:01 AM, Jill Hollenbach wrote:> > Hi all, > I think this is a very basic question, but I'm new to this so > please bear > with me. > > I'm using match to translate elements of a data frame using a > lookup table. > If the content of a particular cell is not found in the lookup > table, the > function returns NA. I'm wondering how I can just ignore those > cells, and > return the original contents if no match is found in the lookup table. > > Many thanks in advance, this site has been extremely helpful for me > so far, > JillIt's not clear to me just what you want to accomplish, but it's possible that setting nomatch=0 in your call to match() might get you somewhere. Note that xxx[c(0,1,2,3] gives xxx[c(1,2,3)] whereas xxx[c(NA,1,2,3)] gives c(NA,xxx[c(1,2,3)]). cheers, Rolf Turner ###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
Let me clarify: I'm using this-- dfnew<- sapply(df, function(df) lookuptable[match(df, lookuptable [ ,1]), 2])>lookup0101 01:01 0201 02:01 0301 03:01 0401 04:01>df0101 0301 0201 0401 0101 0502>dfnew01:01 03:01 02:01 04:01 01:01 NA but what I want is:>dfnew201:01 03:01 02:01 04:01 01:01 0502 thanks again, Jill Jill Hollenbach wrote:> > Hi all, > I think this is a very basic question, but I'm new to this so please bear > with me. > > I'm using match to translate elements of a data frame using a lookup > table. If the content of a particular cell is not found in the lookup > table, the function returns NA. I'm wondering how I can just ignore those > cells, and return the original contents if no match is found in the lookup > table. > > Many thanks in advance, this site has been extremely helpful for me so > far, > Jill > > Jill Hollenbach, PhD, MPH > Assistant Staff Scientist > Center for Genetics > Children's Hospital Oakland Research Institute > jhollenbach at chori.org >-- View this message in context: http://www.nabble.com/how-to-have-%27match%27-ignore-no-matches-tp25756601p25757009.html Sent from the R help mailing list archive at Nabble.com.