Skip to content
Advertisement

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 culomn1 IN (1, 0) AND culomn2 IN (9, 12)')

Advertisement

Answer

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 culomn1 IN (1, 0) AND culomn2 IN (9, 12)
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement