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
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
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
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
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
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
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
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
8 matches
Mail list logo