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

Re: [R] problem with if else statement

2010-06-08 Thread Petr PIKAL
Hi r-help-boun...@r-project.org napsal dne 08.06.2010 11:46:17: > Hi, > > You are using if/then/else which is a logical control statement and so doesn't > return a value, see > ?if > for details. > > You are probably looking for the ifelse function. Or use possibility of easy conversion logi

Re: [R] problem with if else statement

2010-06-08 Thread Martyn Byng
Hi, You are using if/then/else which is a logical control statement and so doesn't return a value, see ?if for details. You are probably looking for the ifelse function. Martyn -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Pe

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

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
You can use the "ifelse" function for vectorized conditionals like you have here. See ?ifelse. From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of Arthur Burke [art.bu...@educationnorthwest.org] Sent: Tuesday, December 08, 2009