Hello there, I got a small problem about logical calculation: we can get a sequene from a+b as below: > a<-c(1,2)> b<-c(3,4) > a+b[1] 4 6 but when the sequences are logical. (I want to get (True,False) && (True, True) ==> (True, False), but when I do as below.> e<-c(T,T) > f<-c(F,T) > e[1] TRUE TRUE> f[1] FALSE TRUE> g<-e && f**g becomes one logical value only> g[1] FALSE>what should I do when I want to get a sequence for operate && or ||? kind regards Yu [[alternative HTML version deleted]]
Well, you just have to use "&", "|" instead of "&&", "||". Best, Mathieu Yuan Jian a ?crit :> Hello there, > > I got a small problem about logical calculation: > we can get a sequene from a+b as below: > > > a<-c(1,2) > >> b<-c(3,4) >> a+b >> > [1] 4 6 > > but when the sequences are logical. (I want to get (True,False) && (True, True) ==> (True, False), but when I do as below. > >> e<-c(T,T) >> f<-c(F,T) >> e >> > [1] TRUE TRUE > >> f >> > [1] FALSE TRUE > >> g<-e && f >> > **g becomes one logical value only > >> g >> > [1] FALSE > > what should I do when I want to get a sequence for operate && or ||? > > kind regards > Yu > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Institute of Mathematics Ecole Polytechnique F?d?rale de Lausanne STAT-IMA-FSB-EPFL, Station 8 CH-1015 Lausanne Switzerland http://stat.epfl.ch/ Tel: + 41 (0)21 693 7907
Use just "&" or "|", these perform element wise,> c(1,2) && c(0,1)[1] FALSE> c(1,2) & c(0,1)[1] FALSE TRUE [[alternative HTML version deleted]]
Use the vector versions: & and | Cheers, Simon. On Sun, 2008-04-13 at 23:48 -0700, Yuan Jian wrote:> Hello there, > > I got a small problem about logical calculation: > we can get a sequene from a+b as below: > > > a<-c(1,2) > > b<-c(3,4) > > a+b > [1] 4 6 > > but when the sequences are logical. (I want to get (True,False) && (True, True) ==> (True, False), but when I do as below. > > e<-c(T,T) > > f<-c(F,T) > > e > [1] TRUE TRUE > > f > [1] FALSE TRUE > > g<-e && f > **g becomes one logical value only > > g > [1] FALSE > > > what should I do when I want to get a sequence for operate && or ||? > > kind regards > Yu > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel-- Simon Blomberg, BSc (Hons), PhD, MAppStat. Lecturer and Consultant Statistician Faculty of Biological and Chemical Sciences The University of Queensland St. Lucia Queensland 4072 Australia Room 320 Goddard Building (8) T: +61 7 3365 2506 http://www.uq.edu.au/~uqsblomb email: S.Blomberg1_at_uq.edu.au Policies: 1. I will NOT analyse your data for you. 2. Your deadline is your problem. The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. - John Tukey.
Berwin A Turlach <berwin@maths.uwa.edu.au> wrote: G'day Yu, On Sun, 13 Apr 2008 23:48:33 -0700 (PDT) Yuan Jian wrote:> what should I do when I want to get a sequence for operate && or ||?Read `help("&&")' and then use & and |. :) HTH. Cheers, Berwin =========================== Full address ============================Berwin A Turlach Tel.: +65 6515 4416 (secr) Dept of Statistics and Applied Probability +65 6515 6650 (self) Faculty of Science FAX : +65 6872 3919 National University of Singapore 6 Science Drive 2, Blk S16, Level 7 e-mail: statba@nus.edu.sg Singapore 117546 http://www.stat.nus.edu.sg/~statba [[alternative HTML version deleted]]