Filtering a data frame by values in a column [duplicate]

Solution 1:

The subset command is not necessary. Just use data frame indexing

studentdata[studentdata$Drink == 'water',]

Read the warning from ?subset

This is a convenience function intended for use interactively. For programming it is better to use the standard subsetting functions like ‘[’, and in particular the non-standard evaluation of argument ‘subset’ can have unanticipated consequences.

Solution 2:

Try this:

subset(studentdata, Drink=='water')

that should do it.

Solution 3:

Thought I'd update this with a dplyr solution

library(dplyr)    
filter(studentdata, Drink == "water")