Hello, writing some R code to cleanse a data set, if the following set of symbols are identified then perform some actions. trying to write the minimum code to do this. tname = "VIX" checkticker = c("VIX", "TYX", "TNX", "IRX") if (tname == checkticker) { //perform some operations } result i get is > tname == checkticker [1] TRUE FALSE FALSE FALSE how do i evaluate this whole list to a single boolean True or False? If any of these are true the whole statement is True, else False. this only seems to work for the first ticker, the rest don't perform the operations within the loop. > tname = "IRX" > tname == checkticker [1] FALSE FALSE FALSE TRUE
zubin-2 wrote:> > > how do i evaluate this whole list to a single boolean True or False? If > any of these are true the whole statement is True, else False. this > only seems to work for the first ticker, the rest don't perform the > operations within the loop. > >Try %in% tname %in% checkticker -Charlie ----- Charlie Sharpsteen Undergraduate Environmental Resources Engineering Humboldt State University -- View this message in context: http://www.nabble.com/evaluate-a-set-of-symbols-within-an-IF-statement-tp25620871p25620900.html Sent from the R help mailing list archive at Nabble.com.
?any -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of zubin > Sent: Friday, September 25, 2009 6:00 PM > To: r-help at r-project.org > Subject: [R] evaluate a set of symbols within an IF statement > > Hello, writing some R code to cleanse a data set, if the following set > of symbols are identified then perform some actions. trying to write > the minimum code to do this. > > > tname = "VIX" > checkticker = c("VIX", "TYX", "TNX", "IRX") > > if (tname == checkticker) { > //perform some operations > } > > result i get is > > > tname == checkticker > [1] TRUE FALSE FALSE FALSE > > how do i evaluate this whole list to a single boolean True or False? > If > any of these are true the whole statement is True, else False. this > only seems to work for the first ticker, the rest don't perform the > operations within the loop. > > > > tname = "IRX" > > tname == checkticker > [1] FALSE FALSE FALSE TRUE > > ______________________________________________ > 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.
Jorge Ivan Velez
2009-Sep-26 21:45 UTC
[R] evaluate a set of symbols within an IF statement
Hi zubin, Try also tname = "VIX" checkticker = c("VIX", "TYX", "TNX", "IRX") is.element(tname, checkticker) # [1] TRUE HTH, Jorge On Fri, Sep 25, 2009 at 8:00 PM, zubin <binabina@bellsouth.net> wrote:> Hello, writing some R code to cleanse a data set, if the following set of > symbols are identified then perform some actions. trying to write the > minimum code to do this. > > tname = "VIX" > checkticker = c("VIX", "TYX", "TNX", "IRX") > > if (tname == checkticker) { > //perform some operations > } > > result i get is > > > tname == checkticker > [1] TRUE FALSE FALSE FALSE > > how do i evaluate this whole list to a single boolean True or False? If > any of these are true the whole statement is True, else False. this only > seems to work for the first ticker, the rest don't perform the operations > within the loop. > > > > tname = "IRX" > > tname == checkticker > [1] FALSE FALSE FALSE TRUE > > ______________________________________________ > 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]]