Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有一种简单的方法可以从R中的大数据帧中减去一个小数据帧?_R - Fatal编程技术网

有没有一种简单的方法可以从R中的大数据帧中减去一个小数据帧?

有没有一种简单的方法可以从R中的大数据帧中减去一个小数据帧?,r,R,我有一个数据集被清理和排序,但不幸的是有人把一些数据放了两次。在R中有没有一种简单的方法,比如说,将重复的子集作为数据帧读入,然后从大数据帧中减去它以消除重复 澄清一下,有些数据确实出现过多次,因此仅仅存在一条重复的行并不意味着数据在合并了两次的较小数据集中。这是一种缓慢而可怕的方法,但它可以完成工作 #Setting up data which has the A row 3 times, the B row twice, and the C row 3 times whichLet <

我有一个数据集被清理和排序,但不幸的是有人把一些数据放了两次。在R中有没有一种简单的方法,比如说,将重复的子集作为数据帧读入,然后从大数据帧中减去它以消除重复


澄清一下,有些数据确实出现过多次,因此仅仅存在一条重复的行并不意味着数据在合并了两次的较小数据集中。

这是一种缓慢而可怕的方法,但它可以完成工作

#Setting up data which has the A row 3 times, the B row twice, and the C row 3 times
whichLet <- c("A","A","A","B","B","C","C","C")
A <-data.frame(Dog=1,Bob=2,Cat=3)
B <-data.frame(Dog=2,Bob=1,Cat=3)
C <- data.frame(Dog=3,Bob=2,Cat=1)
someDuplicates <- do.call(rbind,sapply(whichLet,get,simplify=FALSE))
# Specifying to remove one of the A rows and one of the C rows, this is the same as
toRemove <- do.call(rbind,sapply(c("A","C"),get,simplify=FALSE))
# we now have the data frames you mentioned

while (nrow(toRemove) > 0) { #keep doing this until we've removed all the rows you specified
  uniqueDF <- unique(someDuplicates)
  duplicatedDF <- someDuplicates[duplicated(someDuplicates),]
  # removing the first row of toRemove from uniqueDF
  uniqueDF <- uniqueDF[!apply(apply(uniqueDF,1,function(x) {x==toRemove[1,]}),2,all),]
  # merging the unique back with the duplicates
  someDuplicates <- rbind(uniqueDF,duplicatedDF)
  # removing the item just removed from toRemove
  toRemove <- toRemove[-1,]
}
#设置包含3次A行、2次B行和3次C行的数据

whichLet。。。所以允许有一些重复的行。。。因此,您只想删除其他数据框中的重复行?是的,对于小数据框中的每一行,我想在大数据框中找到该行的一个实例并将其删除。非常感谢。当我再次遇到此问题时,这将非常有用。我刚刚意识到,我的特定数据集有一个让我走捷径的怪癖:小数据集行是唯一的(在合并形成大数据集的其他子集中找不到)。因此,我导出到文本,并在bashshell中执行
grep-vfsall.txt big.txt>big2.txt;cat small.txt>>big2.txt;排序big2.txt>big.txt