给定一个数据框 "foo",如何选择只有那些符合条件 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
期望的结果是"bar":
# location x y
# 2 there 2 7
# 4 there 4 9
subset()
不是首选方法吗?详细讨论请参见此处。 - Chetan Arvind Patilfoo[foo$location == '"there",5:8]
如果我尝试像这样为它们分配一个值,会发生什么:foo[foo$location == "there",5:8] <-FALSE
- Sumedha Nagpal