-2

First question i've ever asked here so bear with me.

Currently working in a data frame which needs multiple filtering & selection steps. Now I need to filter the frame on 2 columns in which the values need to match. So unmatched values, effectively rows, need to be filtered out.

Hopefully this is sufficient information. If not please ask for clarification, data or images.

Thanks in advance.

LyzandeR
  • 37,047
  • 12
  • 77
  • 87
  • 4
    Welcome to SO. Please consider reading up on [ask] and how to create a [reproducible example in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). It makes it easier for others to help you. – Heroka Nov 09 '15 at 11:36
  • Please read [An Introduction to R](https://cran.r-project.org/doc/manuals/R-intro.pdf). – Roland Nov 09 '15 at 11:49
  • Thanks Batanichek. That seems to have done it effectively enough. – user5542172 Nov 09 '15 at 12:01

1 Answers1

0

Hard to tell what exactly you are after, but it sounds like what you need is something along the lines of

x <- "enter value to be matched in col1 here" y <- "enter value to be matched in col2 here" df2 <- df1[df1$col1 == x & df1$col2 == y,]

col1 is the name of the first column in your data frame that you want to filter on, x the value you are looking for in that column (col1). col2 is the name of the second column in your data frame that you want to filter on, y the value you are looking for in that column (col2).

df2 then is a new data frame that only contains those rows of df1 that have x in col1 and y in col2.

John Paper
  • 83
  • 7