好多天没更新了,刚才在一个微信群里有人问如何查看两个dataset的相同或不同数据,我尝试做了一下。
library(dplyr)
a <- c( "扁蓿","草食蚕", "车前","臭蒿", "垂穗鹅冠草", "垂穗披碱草" ,"刺儿菜" ,
"点地梅" , "独活", "多枝黄芪" , "鹅绒委玲菜" ,"繁缕")
b <- c("点地梅", "独活" , "多枝黄芪", "鹅绒委玲菜", "繁缕" ,
"防风" , "风毛菊" , "凤毛菊" , "狗娃花" ,"蒿", "堇菜" , "巨头棘" )
a <- as.data.frame(a)
b <- as.data.frame(b)
colnames(b) <- c("a")
##合并两个数据集
df <- as.data.frame(dplyr::bind_rows(a,b))
##查看不同的物种
unique(df$a)
###[1] "扁蓿" "草食蚕" "车前" "臭蒿" "垂穗鹅冠草" "垂穗披碱草" "刺儿菜" "点地梅" "独活"
##[10] "多枝黄芪" "鹅绒委玲菜" "繁缕" "防风" "风毛菊" "凤毛菊" "狗娃花" "蒿" "堇菜"
##[19] "巨头棘"
dif <- as.data.frame(unique(df$a))
###查看相同的物种
df$a[duplicated(df$a)]
###[1] "点地梅" "独活" "多枝黄芪" "鹅绒委玲菜" "繁缕"
same <- as.data.frame(df$a[duplicated(df$a)])