Quantcast
Channel: Subset / filter rows in a data frame based on a condition in a column - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Subset / filter rows in a data frame based on a condition in a column

$
0
0

Given a data frame "foo", how can I select only those rows from "foo" where e.g. foo$location = "there"?

foo = data.frame(location = c("here", "there", "here", "there", "where"), x = 1:5, y = 6:10)foo#   location x  y# 1     here 1  6# 2    there 2  7# 3     here 3  8# 4    there 4  9# 5    where 5 10

Desired result, "bar":

#   location x y# 2    there 2 7# 4    there 4 9

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>