当单元格相等时删除行 [英] Remove rows when cells are equal
本文介绍了当单元格相等时删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张桌子:
df <- read.table(text="
a b 5
a a 2
c a 3
d d 2
a a 1
b d 2 ")
colnames(df) <- c("Gen1","Gen2", "N")
当Gen1 = Gen2时,我想删除行. 例如,我将得到以下示例:
I would like to remove the rows when Gen1 = Gen2. For example I would get for this example:
result <- read.table(text="
a b 5
c a 3
b d 2 ")
colnames(df) <- c("Gen1","Gen2", "N")
我尝试使用重复项,但是重复项是按行而不是按列工作的.
I tried with duplicated but duplicate is working per rows, not columns.
推荐答案
我们可以使用subset
subset(df, Gen1!=Gen2)
或filter
来自tidyverse
library(tidyverse)
df %>%
filter(Gen1 != Gen2)
数据
df[1:2] <- lapply(df[1:2], as.character)
这篇关于当单元格相等时删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文