comparing three vectors

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

comparing three vectors

arunkumar1111
Hi

I 've a data

a=c(10,20,30)
b=c(100,200,300)
c=c(50,60,70)

I want to compare a[1]<=c[1]<b[1],......

How to compare for all the records
Thanks in Advance
        Arun
Reply | Threaded
Open this post in threaded view
|

Re: comparing three vectors

andrija djurovic
Hi. Try this:

a<=c & c<b

Andrija

On Tue, Jul 17, 2012 at 9:02 AM, arunkumar1111 <[hidden email]> wrote:

> Hi
>
> I 've a data
>
> a=c(10,20,30)
> b=c(100,200,300)
> c=c(50,60,70)
>
> I want to compare a[1]<=c[1]<b[1],......
>
> How to compare for all the records
>
> -----
> Thanks in Advance
>         Arun
> --
> View this message in context:
> http://r.789695.n4.nabble.com/comparing-three-vectors-tp4636728.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: comparing three vectors

arun kirshna
In reply to this post by arunkumar1111


Hi,

Try this:

dat1<-data.frame(a,b,c)
dat1[a<=c& b>c,"abc_check"]<-TRUE
> dat1
   a   b  c abc_check
1 10 100 50      TRUE
2 20 200 60      TRUE
3 30 300 70      TRUE
#or
dat1<-within(dat1,{abc_check<-ifelse(a<=c & b>c,"TRUE","FALSE")})
 dat1
   a   b  c abc_check
1 10 100 50      TRUE
2 20 200 60      TRUE
3 30 300 70      TRUE



A.K.




----- Original Message -----
From: arunkumar1111 <[hidden email]>
To: [hidden email]
Cc:
Sent: Tuesday, July 17, 2012 3:02 AM
Subject: [R] comparing three vectors

Hi

I 've a data

a=c(10,20,30)
b=c(100,200,300)
c=c(50,60,70)

I want to compare a[1]<=c[1]<b[1],......

How to compare for all the records

-----
Thanks in Advance
        Arun
--
View this message in context: http://r.789695.n4.nabble.com/comparing-three-vectors-tp4636728.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.