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