0

I'm using a linked server that won't let me download new R packages (meaning I can only use base R). I know how to filter and select using dplyr and tidyverse but how can I select only rows for a new data.frame (students.bio) that meet the condition of students%subject == "Biology"? Here is what I have tried so far:

students.bio <- students[which(students$subject == "Biology"), ]
students.bio <- Filter(students$subject == "Biology", students)

The first results in an empty df and the second says it can't find a function in the first argument.

I'm new to R so appreciate any help!

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68
Jess
  • 13
  • 6
  • Try `students[students$subject == "Biology", ]` or `subset(students, subject == "Biology")` – Maurits Evers Jul 31 '18 at 00:15
  • Maybe the string `students$subject` has no `"Biology"` in it Maybe it has `" Biology "` or different formats of Biology. I guess you should take that into consideration – Onyambu Jul 31 '18 at 00:18
  • As an aside, `Filter` needs a function as the first argument, like `Filter(function(x) x>=6, 1:10)`. It also won't work nicely on `data.frames` to subset rows as it was built for vectors, and will actually subset columns from a `data.frame` - `Filter(function(x) any(x>=6), data.frame(a=1:10,b=rep(0,10)))` for instance. – thelatemail Jul 31 '18 at 00:30

0 Answers0