在R中使用变量字符串条件从数据框中提取行

时间:2022-06-12 17:02:41

Take iris as the data frame, I want to extract all rows and column variables (Petal.Length,Petal.Width,Sepal.Length,Sepal.Width) that have species as a specific value. e.g setosa. it should show 50 entries. I tried aggregate but didnt work. It is the equivalent and of the WHERE clause in SQL.

将虹膜作为数据框,我想提取所有具有物种作为特定值的行和列变量(Petal.Length,Petal.Width,Sepal.Length,Sepal.Width)。例如塞托萨。它应该显示50个条目。我尝试了聚合但没有工作。它是SQL中的等效和WHERE子句。

1 个解决方案

#1


1  

You are looking for the subset command.

您正在寻找子集命令。

data(iris)

dat<-subset(iris,subset=Species=='setosa')

#1


1  

You are looking for the subset command.

您正在寻找子集命令。

data(iris)

dat<-subset(iris,subset=Species=='setosa')