tyler | 3 Dec 19:13
Picon

Re: Selecting levels from a list

Jeffrey_Warren@... writes:

> I'm trying to select multiple levels from a list of factors but have not
> been able to.  Here is the list:
>
>
> And the code I've tried so far:
>
> lesc.ddl$p$time==0.75 | 1.75 | 2.75  #returns all 'TRUE' values
>
> lesc.ddl$p$time==c(0.75 | 1.75 | 2.75)  #returns all 'FALSE' values
>

Owen already gave you the solution. FYI, Your code didn't work because R
didn't see what you thought it saw.

  lesc.ddl$p$time==0.75 | 1.75 | 2.75

gets interpreted as 

  (lesc.ddl$p$time==0.75) | 1.75 | 2.75

The first part is true when time == 0.75. The second part, 1.75, is
always true (i.e., not zero or false), so the expression as a whole is
always true. Similarly,

  lesc.ddl$p$time==c(0.75 | 1.75 | 2.75)

gets interpreted as

  lesc.ddl$p$time==TRUE

which is FALSE for any value of lesc.ddl$p$time other than 1.

What you could have used was:

  lesc.ddl$p$time==0.75 | lesc.ddl$p$time==1.75 | lesc.ddl$p$time==2.75

This is awkward, which makes the %in% function that Owen recommended
easier to deal with.

Cheers,

Tyler

--

-- 
Who is your computer working for?

http://www.defectivebydesign.org/faq

Gmane