Re: [R] Logical vector question

From: Joshua Wiley <jwiley.psych_at_gmail.com>
Date: Tue, 08 Jun 2010 15:42:58 -0700

Hello,

This should work

v1 <- runif(20, min=0, max=1)
v2 <- v1 <.3 | v1 >.7 #you just need one | not two

HTH, Josh

On Tue, Jun 8, 2010 at 3:38 PM, Worik R <worikr_at_gmail.com> wrote:
> If I create a vector thusly
>
>> v1 <- runif(20, min=0, max=1)
>> v1
>  [1] 0.9754443 0.6306228 0.3238158 0.3175769 0.6791534 0.6956507 0.3840803
>  [8] 0.1421328 0.8592398 0.4388306 0.9472040 0.4727435 0.5645302 0.7391616
> [15] 0.6116199 0.2727754 0.2657867 0.5261744 0.8764804 0.2032126
>
> And I want to create a logical vector the same length that is true if v1<.3
> or v1 > .7  how do I do it without a loop?
>
>> v1>.7
>  [1]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE  TRUE FALSE
> [13] FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE
>> v1<.3
>  [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
> [13] FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE  TRUE
>
> OK so far but I try...
>> v1<.3 || v1>.7
> [1] TRUE
>>
>
> Not a vector.
>
> I have tried a lot of combinations culminating in...
>
> ifelse(((v1<.3) || (v1>.7)), TRUE, FALSE)
> [1] TRUE
>>
>
> What can I do?
>
> cheers
> Worik
>
>
>
>> v1
>  [1] 1 1 1 0 0 0 0 0 0 1
>> v2
>  [1] 1 1 1 0 1 0 0 0 1 1
>
> The
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org 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.
>

-- 
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/

______________________________________________
R-help_at_r-project.org 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.
Received on Tue 08 Jun 2010 - 22:45:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 08 Jun 2010 - 23:00:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive