[R-sig-eco] Selecting levels from a list
Owen Jones
owen.jones at imperial.ac.uk
Wed Dec 3 17:59:32 CET 2008
Try the %in% notation which works like this:
> x<-as.factor(LETTERS[1:10])
> x
[1] A B C D E F G H I J
Levels: A B C D E F G H I J
> x[x%in%c("C","J")]
[1] C J
Levels: A B C D E F G H I J
Cheers,
Owen
On Wed, Dec 3, 2008 at 4:46 PM, <Jeffrey_Warren at fws.gov> wrote:
>
> I'm trying to select multiple levels from a list of factors but have not
> been able to. Here is the list:
>
> lesc.ddl$p$time
> [1] 0.75 0.833 1 1.75 1.833 2 2.75 2.833 3 3.75 3.833 4
> 0.833 1 1.75 1.833 2 2.75 2.833 3 3.75 3.833 4 1
> 1.75
> [26] 1.833 2 2.75 2.833 3 3.75 3.833 4 1.75 1.833 2 2.75
> 2.833 3 3.75 3.833 4 1.833 2 2.75 2.833 3 3.75 3.833 4
> [51] 2 2.75 2.833 3 3.75 3.833 4 2.75 2.833 3 3.75
> 3.833 4 2.833 3 3.75 3.833 4 3 3.75 3.833 4 3.75
> 3.833 4
> [76] 3.833 4 4
> Levels: 0.75 0.833 1 1.75 1.833 2 2.75 2.833 3 3.75 3.833 4
>
> 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
>
> Any help would be greatly appreciated.
>
> Cheers,
>
> Jeff Warren
> Wildlife Biologist
> Red Rock Lakes NWR
> Lima, Montana 59739
> (406) 276-3536
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>
--
Dr Owen Jones
Imperial College London,
Silwood Park Campus,
Ascot.
SL5 7PY
UK
Tel: +44(0)20 75942489
Email: owen.jones at imperial.ac.uk
Website:http://www3.imperial.ac.uk/people/owen.jones
More information about the R-sig-ecology
mailing list