gpt4 book ai didi

R:从一个数据框中删除在另一数据框中的行

转载 作者:行者123 更新时间:2023-12-04 03:45:28 24 4
gpt4 key购买 nike

我有两个数据帧df1和df2。它们具有相同(两列)的列。我想从df2中的df1中删除行。

最佳答案

您可以使用几个软件包来做到这一点。但是,这是使用基数R的方法。

df1 <-matrix(1:6,ncol=2,byrow=TRUE)
df2 <-matrix(1:10,ncol=2,byrow=TRUE)
all <-rbind(df1,df2) #rbind the columns
#use !duplicated fromLast = FALSE and fromLast = TRUE to get unique rows.
all[!duplicated(all,fromLast = FALSE)&!duplicated(all,fromLast = TRUE),]

[,1] [,2]
[1,] 7 8
[2,] 9 10

关于R:从一个数据框中删除在另一数据框中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10907359/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com