【问题标题】:some problems with dplyr and full join optiondplyr 和完全加入选项的一些问题
【发布时间】:2019-06-16 11:49:50
【问题描述】:

我会用 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))

【问题讨论】:

  • 两个对象都需要是数据框,full_join 才能工作。如果Mouth_tissuesclass()Glands 不是data.frame,则连接将不起作用。
  • 好的。谢谢。如何将它们转换为数据框?
  • 您能否将dput(head(counts_sample_gland0))dput(head(counts_sample_mouth0)) 的输出添加到您的问题中?
  • 好的!我做到了……
  • 不,我的意思是这两行的 输出 如果你将它们粘贴到你的 R shell 中。 R 输出将类似于 structure(list(...

标签: r dplyr


【解决方案1】:

我认为这就是你想要做的?

已使用“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)

【讨论】:

  • 问题是我有28000个基因
  • 无论是两行数据还是28K,都应该是一样的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-19
  • 1970-01-01
  • 2019-12-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多