根据 R 中的列值删除行
Removing Rows Based on Column Value in R
我在 R 中有一个简单的 table 名为 Tag_Count
:
Tag 1 freq
Cookies 1
Cakes 2
Burritos 5
我想删除频率值小于 3 的所有行。我试过:
Tag_Count_2 <- Tag_Count[Tag_Count$freq <= 3,]
Tag_Count_2 <- Tag_Count[freq < 4]
但都没有用。
我们可以试试
Tag_Count[!(Tag_Count$freq <= 3),]
如果这不是 data.frame
,则
Tag_Count[!(Tag_Count[,"freq"] <= 3),]
你可以试试这个
library(dplyr)
df1 <- df %>%
filter(freq >= 3)
print(df1)
Tag1 freq
1 Burritos 5
data
df <- data.frame(Tag1 = c("Cookies","Cakes","Burritos"),freq = c(1,2,5), stringsAsFactors = F)
我在 R 中有一个简单的 table 名为 Tag_Count
:
Tag 1 freq
Cookies 1
Cakes 2
Burritos 5
我想删除频率值小于 3 的所有行。我试过:
Tag_Count_2 <- Tag_Count[Tag_Count$freq <= 3,]
Tag_Count_2 <- Tag_Count[freq < 4]
但都没有用。
我们可以试试
Tag_Count[!(Tag_Count$freq <= 3),]
如果这不是 data.frame
,则
Tag_Count[!(Tag_Count[,"freq"] <= 3),]
你可以试试这个
library(dplyr)
df1 <- df %>%
filter(freq >= 3)
print(df1)
Tag1 freq
1 Burritos 5
data
df <- data.frame(Tag1 = c("Cookies","Cakes","Burritos"),freq = c(1,2,5), stringsAsFactors = F)