Getting data from 2 columns in a data frame

From an object named “education,” which contains the contents of a CSV file, I want to extract those rows in which the column Region (column 3) is equal to 3 and the column Minor.Population (column 6) is greater than 310, and then view the results so that I can do an analysis of their contents.

How can I do that?

Here is one way using the dplyr package.

df <- filter(education, Region == 3, Minor.Population > 310)

Thank you. Any idea about how many bytes are in the dplyr package?

I found the answer. It is 6.5 MB.

When I run it in RStudio, I get this error message: >
"Error in match.arg(method) : object 'Minor.Population' not found"

However, this code works, so Minor.Population is the correct column name:

Any idea why?

If you do not want to use the dplyr package you can use base R.

df <- education[education$Region == 3 & education$Minor.Population > 310, ]

I would like to use the dplyr package. Any idea what is causing the error?

This might be an instance of conflicting function names. See here for example

Does the following work?

df <- dplyr::filter(education, Region == 3, Minor.Population > 310)

To help us help you, and to avoid these back and forths, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

When I entered "?filter" I got this: " Linear Filtering on a Time Series," so there appears to be a second "filter" function, and they conflict. Your revision with "dplyr::filter" worked.

Thanks again. I appreciate your help.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.