W dniu 2011-06-08 04:24, Anamika Chaudhuri pisze:
> Hi All:
>
> I need to ask a very simple question. I am trying to code the
> following if then else statement in R.
>
> If low_cl<p<up_cl then coverage=1;
> else coverage=0;
>
> Any help will be appreciated.
Hi, Anamika, it's me again :)
As a former C/Pascal programmer I am addicted to semicolons; you didnt't
need them in the previous example.
You may also write it in more tricky way:
> low_cl<-1.0
> high_cl<-3.0
> p<-0.5
> coverage<-(low_cl<p && p<high_cl)+0
> coverage
[1] 0
> p<-1.5
> coverage<-(low_cl<p && p<high_cl)+0
> coverage
[1] 1
> p<-3.0
> coverage<-(low_cl<p && p<high_cl)+0
> coverage
[1] 0
>
Certainly the previous code was more readable.
It appears in R you cannot do it in the way like this:
>coverage<-(low_cl<p && p<high_cl)?0:1
as you could in C or PHP, for instance.
Regards
W.Jawien
-------------------------------------------------------------------
This list is for discussion of modelling issues and the BUGS software.
For help with crashes and error messages, first mail [log in to unmask]
To mail the BUGS list, mail to [log in to unmask]
Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html
Please do not mail attachments to the list.
To leave the BUGS list, send LEAVE BUGS to [log in to unmask]
If this fails, mail [log in to unmask], NOT the whole list
|