Skip to content

filter a data.frame

6 messages · Mat, arun, Gerrit Eichner +2 more

Mat
#
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.

Maybe anyone can help me.

Thank you.

Mat



--
View this message in context: http://r.789695.n4.nabble.com/filter-a-data-frame-tp4682118.html
Sent from the R help mailing list archive at Nabble.com.
#
Try:

?out[out$No%in% no.ind,]
#? No. text
#2?? 2? def
#3?? 3?? ee
A.K.
On Friday, December 13, 2013 8:03 AM, Mat <matthias.weber at fnt.de> wrote:
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.

Maybe anyone can help me.

Thank you.

Mat



--
View this message in context: http://r.789695.n4.nabble.com/filter-a-data-frame-tp4682118.html
Sent from the R help mailing list archive at Nabble.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.
#
Hello, Mat,

see below.
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.,
See ?is.element.


  Hth  --  Gerrit
#
Hello,

Try instead



no.ind <- c(2, 3)

out1 <- out[out$No %in% no.ind, ]


Hope this helps,

Rui Barradas

Em 13-12-2013 12:59, Mat escreveu: