Re: [R] Problem with if

2012-11-11 Thread Patrick Burns
This is Circle 8.1.30 of 'The R Inferno'. http://www.burns-stat.com/pages/Tutor/R_inferno.pdf The example even uses 3. On 10/11/2012 16:58, David Winsemius wrote: On Nov 10, 2012, at 8:34 AM, Haszun wrote: Why it always gives me a 3? fun=function(x) { + if (x<-3) { The above code assig

Re: [R] Problem with if

2012-11-10 Thread David Winsemius
On Nov 10, 2012, at 8:34 AM, Haszun wrote: > Why it always gives me a 3? > >> fun=function(x) { > + if (x<-3) { The above code assigns 3 to x. > + return(x) > + } else { > + if(x<2) { > + return(x^2-1) > + } else { > + return(log(x)) > + }}} >> >> fun(-5) > [1] 3 >> fun(0) > [1] 3 >> fun(10

Re: [R] Problem with if

2012-11-10 Thread Haszun
Thank you for help. -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-if-tp4649180p4649182.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listi

[R] Problem with if

2012-11-10 Thread Haszun
Why it always gives me a 3? > fun=function(x) { + if (x<-3) { + return(x) + } else { + if(x<2) { + return(x^2-1) + } else { + return(log(x)) + }}} > > fun(-5) [1] 3 > fun(0) [1] 3 > fun(10) [1] 3 > fun(-10) [1] 3 > -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-

Re: [R] problem with if else statement

2010-06-08 Thread Petr PIKAL
ossibility of easy conversion logical (T/F) to numeric (1/0) rr.dia.2m - (med.hyper==1)*5 Regards Petr > > Martyn > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Peter Lercher > Sent: 08 June 2010 10:18

Re: [R] problem with if else statement

2010-06-08 Thread Martyn Byng
lf Of Peter Lercher Sent: 08 June 2010 10:18 To: r-help@r-project.org Subject: [R] problem with if else statement Dear colleagues, What did I not understand ? ->my intention I want to create a new variable: In plain language: If someone is taking anithypertensive treatment (med.hyper==1) table(m

Re: [R] problem with if else statement

2010-06-08 Thread Rafael Björk
Hi Peter! The 'if' function operate on a single logical expression, while you provided a vector. What your code does at present is subtract 5 from all values in rr.dia.2m if the first value in med.hyper is 1 and otherwise simply returns all values as is. Since you have no reproducible data, it's h

[R] problem with if else statement

2010-06-08 Thread Peter Lercher
Dear colleagues, What did I not understand ? ->my intention I want to create a new variable: In plain language: If someone is taking anithypertensive treatment (med.hyper==1) table(med.hyper) med.hyper 0 1 472 97 I want to subtract 5 mmHg (rr.dia.2m-5) from the measured diastolic blood pres

Re: [R] Problem with if statement

2009-12-08 Thread Gabor Grothendieck
It would be easier to answer if a portion of the input were shown in the question using dput(rf) or dput(head(rf)) but lets assume it looks like this and that our objective is to display a table of Name vs. DNAME counts where DNAME consists of manufactured short names -- is that right? DF <- data

Re: [R] Problem with if statement

2009-12-08 Thread Erik Iverson
r 08, 2009 6:45 PM To: r-help@r-project.org Subject: [R] Problem with if statement I am trying to use the value of an ID variable in an if statement and not getting the results I expected. # ID values for two school districts > with(rf, tapply(DistrictID, DistrictName, min) ) Aberdeen Scho

[R] Problem with if statement

2009-12-08 Thread Arthur Burke
I am trying to use the value of an ID variable in an if statement and not getting the results I expected. # ID values for two school districts > with(rf, tapply(DistrictID, DistrictName, min) ) Aberdeen School Dist. # 58 Buhl Joint School District 59