Search code examples
sqlrselectwhere-clausesql-in

Create subset using select in R


I am new to R scripting, I need to create subset of dataset using select function with some condition, I need just two columns not all columns.

This is my code

sqldf('SELECT * FROM dataset WHERE column1 IN (1, 0) AND column2 IN (9, 12)')

Solution

  • In SQL, select * gives you all columns (that's what the * stands for). If you just want some of them, then enumerate them in the select clause, like:

    SELECT column1, column2 FROM dataset WHERE column1 IN (1, 0) AND column2 IN (9, 12)