Message-ID: <Pine.SOC.4.64.1312131517030.1492@solcom.hrz.uni-giessen.de>
Date: 2013-12-13T14:21:42Z
From: Gerrit Eichner
Subject: filter a data.frame
In-Reply-To: <1386939582235-4682118.post@n4.nabble.com>
Hello, Mat,
see below.
> hello together, i want to filter a data.frame. My problem is, that i
> want to filter 2 numbers.
>
> My data.frame look like this one.
>
> No. text
> 1 abc
> 2 def
> 3 ee
> 4 ff
> 5 gg
>
> I want now to filter No. 2 and 3, so my solution should be look like this
> one.
>
> No. text
> 2 def
> 3 ee
>
> i tried it like this one:
> out1<-out[(out$No==no.ind),]
>
> in no.ind i have the 2 numbers: c("2","3")
>
> but this doesn't work.
You should not expect a vector (of two elements), here no.ind, equal
elementwise any of the elements of another (longer) vector, here out$No.
You probably actually want to check for each element of out$No if it is
contained in the set of elements in no.ind. So, use, e.g.,
> out1 <- out[(out$No %in% no.ind),]
See ?is.element.
Hth -- Gerrit