Hi R, This is a very trivial one.... C=0.1 I want to check whether my value of C is between 0 and 1 exclusively.... I don't want to use (C>0 & C<1). And I can't use a single statement like (0<C<1). Is there a between function? Or how do we specify from 0 to 1? Does %in% help me? Many Thanks, Shubha This e-mail may contain confidential and/or privileged i...{{dropped:13}}
On Tue, Aug 12, 2008 at 05:16:01PM +0530, Shubha Vishwanath Karanth wrote:> Hi R, > > > > This is a very trivial one.... > > > > C=0.1 > > > > I want to check whether my value of C is between 0 and 1 exclusively.... > I don't want to use (C>0 & C<1). And I can't use a single statement like > (0<C<1). Is there a between function? Or how do we specify from 0 to 1? > Does %in% help me?If you don't like (C > 0 && C < 1), then just write your own function is.between(x, low, high) (NB1 you've basically written it already; NB2 single '&' for the vectorised version 'are.between'). People's personal tastes about what's desirable will vary, and anyway it's good practice to build up your own personal library of functions. Ultimately if you have a high quality collection of related functions for working on a particular sort of problem, then you should publish them as an R package on CRAN. Dan> > > > > > Many Thanks, > > Shubha > > > > This e-mail may contain confidential and/or privileged i...{{dropped:13}} > > ______________________________________________ > 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.-- www.stats.ox.ac.uk/~davison
Or at least anyways of defining a vector/(or something like that) which has all values between 0 and 1? For example: C(0,1) is incorrect, seq(0,1,0.2) is also incorrect, seq(0,1,0.00001) is also incorrect.... How does one specify this? Thanks, Shubha -----Original Message----- From: Dan Davison [mailto:davison at stats.ox.ac.uk] Sent: Tuesday, August 12, 2008 5:54 PM To: Shubha Vishwanath Karanth Cc: r-help at stat.math.ethz.ch Subject: Re: [R] Between the values On Tue, Aug 12, 2008 at 05:16:01PM +0530, Shubha Vishwanath Karanth wrote:> Hi R, > > > > This is a very trivial one.... > > > > C=0.1 > > > > I want to check whether my value of C is between 0 and 1exclusively....> I don't want to use (C>0 & C<1). And I can't use a single statementlike> (0<C<1). Is there a between function? Or how do we specify from 0 to1?> Does %in% help me?If you don't like (C > 0 && C < 1), then just write your own function is.between(x, low, high) (NB1 you've basically written it already; NB2 single '&' for the vectorised version 'are.between'). People's personal tastes about what's desirable will vary, and anyway it's good practice to build up your own personal library of functions. Ultimately if you have a high quality collection of related functions for working on a particular sort of problem, then you should publish them as an R package on CRAN. Dan> > > > > > Many Thanks, > > Shubha > > > > This e-mail may contain confidential and/or privilegedi...{{dropped:13}}> > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.-- www.stats.ox.ac.uk/~davison This e-mail may contain confidential and/or privileged i...{{dropped:10}}
Thanks Ravi... But was just wondering if there existed a simple tricky command for that without using the & condition.... Also was thinking on my second question that how do we define an interval between 0 and 1 which contains all the values between 0 and 1. Thanks, Shubha Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San Jos? * Singapore * www.ambaresearch.com -----Original Message----- From: Ravi Varadhan [mailto:RVaradhan at jhmi.edu] Sent: Tuesday, August 12, 2008 7:12 PM To: Shubha Vishwanath Karanth; 'Dan Davison' Cc: r-help at stat.math.ethz.ch Subject: RE: [R] Between the values Hi Shubaa, Here is one way to do this: is.between <- function(x, a, b) { x > a & x < b } set.seed(123) x <- rnorm(5) is.between(x, -1, 1)> is.between(x, -1, 1)[1] TRUE TRUE FALSE TRUE TRUE>Ravi. -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Shubha Vishwanath Karanth Sent: Tuesday, August 12, 2008 9:25 AM To: Dan Davison Cc: r-help at stat.math.ethz.ch Subject: Re: [R] Between the values Or at least anyways of defining a vector/(or something like that) which has all values between 0 and 1? For example: C(0,1) is incorrect, seq(0,1,0.2) is also incorrect, seq(0,1,0.00001) is also incorrect.... How does one specify this? Thanks, Shubha -----Original Message----- From: Dan Davison [mailto:davison at stats.ox.ac.uk] Sent: Tuesday, August 12, 2008 5:54 PM To: Shubha Vishwanath Karanth Cc: r-help at stat.math.ethz.ch Subject: Re: [R] Between the values On Tue, Aug 12, 2008 at 05:16:01PM +0530, Shubha Vishwanath Karanth wrote:> Hi R, > > > > This is a very trivial one.... > > > > C=0.1 > > > > I want to check whether my value of C is between 0 and 1exclusively....> I don't want to use (C>0 & C<1). And I can't use a single statementlike> (0<C<1). Is there a between function? Or how do we specify from 0 to1?> Does %in% help me?If you don't like (C > 0 && C < 1), then just write your own function is.between(x, low, high) (NB1 you've basically written it already; NB2 single '&' for the vectorised version 'are.between'). People's personal tastes about what's desirable will vary, and anyway it's good practice to build up your own personal library of functions. Ultimately if you have a high quality collection of related functions for working on a particular sort of problem, then you should publish them as an R package on CRAN. Dan> > > > > > Many Thanks, > > Shubha > > > > This e-mail may contain confidential and/or privilegedi...{{dropped:13}}> > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.-- www.stats.ox.ac.uk/~davison This e-mail may contain confidential and/or privileged i...{{dropped:10}} ______________________________________________ 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. This e-mail may contain confidential and/or privileged i...{{dropped:10}}
Thanks....Didn't mean actually using '&', but not bigger than that too... I usually see something done much better in R-help by a code which I don't know at all. So, wanted to know if I am missing somewhere in using some codes which I am not aware of...so, posted the query... Thanks for your help, Shubha Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San Jos? * Singapore * www.ambaresearch.com -----Original Message----- From: Ravi Varadhan [mailto:RVaradhan at jhmi.edu] Sent: Tuesday, August 12, 2008 7:34 PM To: Shubha Vishwanath Karanth; 'Dan Davison' Cc: r-help at stat.math.ethz.ch Subject: RE: [R] Between the values Here is how you check whether a < x < b "without" using the `&' condition: is.between <- function(x, a, b) { (x - a) * (b - x) > 0 } Ravi. -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Shubha Vishwanath Karanth Sent: Tuesday, August 12, 2008 9:46 AM To: Ravi Varadhan; Dan Davison; Ravi Varadhan; Dan Davison; Ravi Varadhan; Dan Davison; Ravi Varadhan; Dan Davison Cc: r-help at stat.math.ethz.ch; r-help at stat.math.ethz.ch; r-help at stat.math.ethz.ch; r-help at stat.math.ethz.ch Subject: Re: [R] Between the values Thanks Ravi... But was just wondering if there existed a simple tricky command for that without using the & condition.... Also was thinking on my second question that how do we define an interval between 0 and 1 which contains all the values between 0 and 1. Thanks, Shubha Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San Jos? * Singapore * www.ambaresearch.com -----Original Message----- From: Ravi Varadhan [mailto:RVaradhan at jhmi.edu] Sent: Tuesday, August 12, 2008 7:12 PM To: Shubha Vishwanath Karanth; 'Dan Davison' Cc: r-help at stat.math.ethz.ch Subject: RE: [R] Between the values Hi Shubaa, Here is one way to do this: is.between <- function(x, a, b) { x > a & x < b } set.seed(123) x <- rnorm(5) is.between(x, -1, 1)> is.between(x, -1, 1)[1] TRUE TRUE FALSE TRUE TRUE>Ravi. -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Shubha Vishwanath Karanth Sent: Tuesday, August 12, 2008 9:25 AM To: Dan Davison Cc: r-help at stat.math.ethz.ch Subject: Re: [R] Between the values Or at least anyways of defining a vector/(or something like that) which has all values between 0 and 1? For example: C(0,1) is incorrect, seq(0,1,0.2) is also incorrect, seq(0,1,0.00001) is also incorrect.... How does one specify this? Thanks, Shubha -----Original Message----- From: Dan Davison [mailto:davison at stats.ox.ac.uk] Sent: Tuesday, August 12, 2008 5:54 PM To: Shubha Vishwanath Karanth Cc: r-help at stat.math.ethz.ch Subject: Re: [R] Between the values On Tue, Aug 12, 2008 at 05:16:01PM +0530, Shubha Vishwanath Karanth wrote:> Hi R, > > > > This is a very trivial one.... > > > > C=0.1 > > > > I want to check whether my value of C is between 0 and 1exclusively....> I don't want to use (C>0 & C<1). And I can't use a single statementlike> (0<C<1). Is there a between function? Or how do we specify from 0 to1?> Does %in% help me?If you don't like (C > 0 && C < 1), then just write your own function is.between(x, low, high) (NB1 you've basically written it already; NB2 single '&' for the vectorised version 'are.between'). People's personal tastes about what's desirable will vary, and anyway it's good practice to build up your own personal library of functions. Ultimately if you have a high quality collection of related functions for working on a particular sort of problem, then you should publish them as an R package on CRAN. Dan> > > > > > Many Thanks, > > Shubha > > > > This e-mail may contain confidential and/or privilegedi...{{dropped:13}}> > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.-- www.stats.ox.ac.uk/~davison This e-mail may contain confidential and/or privileged i...{{dropped:10}} ______________________________________________ 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. This e-mail may contain confidential and/or privileged i...{{dropped:10}} ______________________________________________ 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. This e-mail may contain confidential and/or privileged i...{{dropped:10}}
Not to define a vector of all infinite values... But if I have some object (may not be a vector) which has this interval, then I can apply whatever function I need to on this interval apart from 'between' function... Is there something like that... Hope I am clear with the idea... Thanks, Shubha Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San Jos? * Singapore * www.ambaresearch.com -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Dan Davison Sent: Tuesday, August 12, 2008 7:21 PM To: r-help at r-project.org Subject: Re: [R] Between the values Shubha Vishwanath Karanth wrote:> > Or at least anyways of defining a vector/(or something like that) which > has all values between 0 and 1? > > For example: > C(0,1) is incorrect, seq(0,1,0.2) is also incorrect, seq(0,1,0.00001) is > also incorrect.... How does one specify this? > >Hi Shubha, What are you trying to do? The set of all real numbers between 0 and 1 is infinitely large. Obviously you can't explicitly construct an infinitely large vector in R. If you want to construct an implicit specification of that set, then I think I've already given you a good answer in R: define a predicate function and use it. E.g. between <- function(x, low, high) x > low && x < high I don't know much at all about symbolic mathematics packages like Maple and Mathematica, but maybe you're thinking of something you can do in those softwares? R is not trying to be a competitor to them; they do lots of things R doesn't, and vice versa. Dan Shubha Vishwanath Karanth wrote:> > > Thanks, Shubha > > > -----Original Message----- > From: Dan Davison [mailto:davison at stats.ox.ac.uk] > Sent: Tuesday, August 12, 2008 5:54 PM > To: Shubha Vishwanath Karanth > Cc: r-help at stat.math.ethz.ch > Subject: Re: [R] Between the values > > On Tue, Aug 12, 2008 at 05:16:01PM +0530, Shubha Vishwanath Karanth > wrote: >> Hi R, >> >> >> >> This is a very trivial one.... >> >> >> >> C=0.1 >> >> >> >> I want to check whether my value of C is between 0 and 1 > exclusively.... >> I don't want to use (C>0 & C<1). And I can't use a single statement > like >> (0<C<1). Is there a between function? Or how do we specify from 0 to > 1? >> Does %in% help me? > > If you don't like (C > 0 && C < 1), then just write your own function > is.between(x, low, high) (NB1 you've basically written it already; NB2 > single '&' for the vectorised version 'are.between'). People's > personal tastes about what's desirable will vary, and anyway it's good > practice to build up your own personal library of > functions. Ultimately if you have a high quality collection of related > functions for working on a particular sort of problem, then you should > publish them as an R package on CRAN. > > Dan > >> >> >> >> >> >> Many Thanks, >> >> Shubha >> >> >> >> This e-mail may contain confidential and/or privileged > i...{{dropped:13}} >> >> ______________________________________________ >> 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. > > -- > www.stats.ox.ac.uk/~davison > This e-mail may contain confidential and/or privileged i...{{dropped:10}} > > ______________________________________________ > 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. > >-- View this message in context: http://www.nabble.com/Between-the-values-tp18943069p18944668.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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. This e-mail may contain confidential and/or privileged i...{{dropped:10}}
SQL has a between operator and via sqldf you can do this using the built in data frame BOD as an example:> library(sqldf) > BODTime demand 1 1 8.3 2 2 10.3 3 3 19.0 4 4 16.0 5 5 15.6 6 7 19.8> sqldf("select demand between 15 and 17 from BOD")demand between 15 and 17 1 0 2 0 3 0 4 1 5 1 6 0>On Tue, Aug 12, 2008 at 7:46 AM, Shubha Vishwanath Karanth <shubhak at ambaresearch.com> wrote:> Hi R, > > > > This is a very trivial one.... > > > > C=0.1 > > > > I want to check whether my value of C is between 0 and 1 exclusively.... > I don't want to use (C>0 & C<1). And I can't use a single statement like > (0<C<1). Is there a between function? Or how do we specify from 0 to 1? > Does %in% help me? > > > > > > Many Thanks, > > Shubha > > > > This e-mail may contain confidential and/or privileged i...{{dropped:13}} > > ______________________________________________ > 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. >
# between (a,b) a <- 0 b <- 1 x <- rnorm(10) x unclass(cut(x, breaks=c(-Inf,a,b,Inf)))==2 -gary -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Shubha Vishwanath Karanth Sent: Tuesday, August 12, 2008 7:46 AM To: r-help at stat.math.ethz.ch Subject: [R] Between the values Hi R, This is a very trivial one.... C=0.1 I want to check whether my value of C is between 0 and 1 exclusively.... I don't want to use (C>0 & C<1). And I can't use a single statement like (0<C<1). Is there a between function? Or how do we specify from 0 to 1? Does %in% help me? Many Thanks, Shubha This e-mail may contain confidential and/or privileged i...{{dropped:13}} ______________________________________________ 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. -------------------------------------------------------- This message w/attachments (message) may be privileged, confidential or proprietary, and if you are not an intended recipient, please notify the sender, do not use or share it and delete it. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Merrill Lynch. Subject to applicable law, Merrill Lynch may monitor, review and retain e-communications (EC) traveling through its networks/systems. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or error-free. This message is subject to terms available at the following link: http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you consent to the foregoing.