R语言交补集数据处理

一、交集——Merge函数

rm(list = ls())
setwd('/lab412C/LSM/蛋白质谱/蛋白质谱-RNA seq/缺少的300个')
data1 <- read.csv(file = "all.csv",header = T,sep = ",")
data2 <- read.csv(file = "deg.csv",header = T,sep = ",")
data3 <- merge(data1,data2,by.X='gene')
data3=data3[!duplicated(data3),] ##删除重复行
write.csv(data3, quote = F,file='/lab412C/LSM/蛋白质谱/蛋白质谱-RNA seq/DEG-Map88个.csv')

二、补集——sqldf函数

rm(list = ls())
library(sqldf)
setwd('/lab412C/LSM/蛋白质谱/蛋白质谱-RNA seq/缺少的300个')
my.dataset <- data1 <- read.csv(file = "all.csv",header = T,sep = ",")
my.dataset1 <- data2 <- read.csv(file = "deg.csv",header = T,sep = ",")
data3 <- sqldf('SELECT * FROM [my.dataset] EXCEPT SELECT * FROM [my.dataset1]')
write.csv(data3, quote = F,file='/lab412C/LSM/蛋白质谱/蛋白质谱-RNA seq/DEG-Map88个.csv')

前提:输入数据的两列必须完全一致!

你可能感兴趣的:(R语言交补集数据处理)