首页 > 解决方案 > dplyr 和完全加入选项的一些问题

问题描述

我会用 diplyr 加入一些表格,但它提醒我一些错误。

我有两个变量,我想加入它们,但它提醒了我一些错误。怎么了?如何使用 dplyr 创建一个在行之间进行正确匹配的表?谢谢

Mouth_tissues= counts_sample_mouth0$counts
Glands= counts_sample_gland0$counts  

head(Mouth_tissues)
  Mouth_tissues
gene0                                                                              547
gene1                                                                               78
gene2                                                                                5
gene3                                                                               13
gene4                                                                               16
gene5                                                                               49
> head(Glands)
  Glands
gene0                                                                                                 332
gene1                                                                                                  60
gene2                                                                                                 583
gene3                                                                                                6964
gene4                                                                                                2162
gene5                                                                                   6
> full_join(Mouth_tissues, Glands)
Error in UseMethod("full_join") : 
no applicable method for 'full_join' applied to an object of class   "c('matrix', 'integer', 'numeric')"

然后我做了:

 mouth<-as.data.frame.matrix(Mouth_tissues)

 glands<-as.data.frame.matrix(Glands)
library(dplyr)

full_join(mouth, glands)
Error: `by` required, because the data sources have no common variables
Call `rlang::last_error()` to see a backtrace




dput(head(counts_sample_gland0))

dput(head(counts_sample_mouth0))

标签: rdplyr

解决方案


我想这就是你想要做的?

已使用“Num”列上的完全连接来连接两个表。

library(tidyverse)

MouthTissue=c("gene0","gene1")
Num=c(547,78)
Mouthtissues_df=data.frame(MouthTissue,Num)

Glands=c("gene0","gene1")
Num=c(332,60)
Glands_df=data.frame(Glands,Num)

fulljoin=dplyr::full_join(Glands_df,Mouthtissues_df)

推荐阅读