代码语言:javascript复制
title: "merge 合并"
output: html_document
date: "2024-03-08"
R Markdown
代码语言:javascript复制suppressMessages(library(TCGAbiolinks))
suppressMessages(library(SummarizedExperiment))
X1 <- assay(met)[1:3,1:3]
X1
代码语言:javascript复制## TCGA-EP-A2KC-01A-11D-A20Z-05 TCGA-ES-A2HS-01A-11D-A17Z-05
## cg16619049 0.7796626 0.4656080
## cg18147296 0.8179045 0.7744908
## cg13938959 0.6397997 0.9317492
## TCGA-ES-A2HS-11A-11D-A17Z-05
## cg16619049 0.5465106
## cg18147296 0.8456720
## cg13938959 0.8302542
代码语言:javascript复制X2 <- assay(met)[2:4,4:6]
X2
代码语言:javascript复制## TCGA-CC-5259-01A-31D-A20Z-05 TCGA-ED-A97K-01A-21D-A383-05
## cg18147296 0.7253149 0.8047118
## cg13938959 0.4120948 0.7887094
## cg12445832 0.1848328 0.7557783
## TCGA-DD-A3A1-01A-11D-A20Z-05
## cg18147296 0.8544879
## cg13938959 0.8174317
## cg12445832 0.1738895
代码语言:javascript复制ya <- merge(X1,X2,by="row.names")
ya#会发现合并之后多了一个row.names行名,怎么把他删除掉呢?
代码语言:javascript复制## Row.names TCGA-EP-A2KC-01A-11D-A20Z-05 TCGA-ES-A2HS-01A-11D-A17Z-05
## 1 cg13938959 0.6397997 0.9317492
## 2 cg18147296 0.8179045 0.7744908
## TCGA-ES-A2HS-11A-11D-A17Z-05 TCGA-CC-5259-01A-31D-A20Z-05
## 1 0.8302542 0.4120948
## 2 0.8456720 0.7253149
## TCGA-ED-A97K-01A-21D-A383-05 TCGA-DD-A3A1-01A-11D-A20Z-05
## 1 0.7887094 0.8174317
## 2 0.8047118 0.8544879
代码语言:javascript复制#我的笨方法
gg <- colnames(ya)#对行名进行赋值
gg1 <- gg[-1]#删掉第一个row.names
rownames(ya) <- NULL
rownames(ya) <- ya[,1]
ya<- ya[-1]
colnames(ya) <- gg1#再次赋值行名
ya
代码语言:javascript复制## TCGA-EP-A2KC-01A-11D-A20Z-05 TCGA-ES-A2HS-01A-11D-A17Z-05
## cg13938959 0.6397997 0.9317492
## cg18147296 0.8179045 0.7744908
## TCGA-ES-A2HS-11A-11D-A17Z-05 TCGA-CC-5259-01A-31D-A20Z-05
## cg13938959 0.8302542 0.4120948
## cg18147296 0.8456720 0.7253149
## TCGA-ED-A97K-01A-21D-A383-05 TCGA-DD-A3A1-01A-11D-A20Z-05
## cg13938959 0.7887094 0.8174317
## cg18147296 0.8047118 0.8544879
代码语言:javascript复制#小洁老师教的方法
ya <- merge(X1,X2,by="row.names")
tibble::column_to_rownames(ya, var = "Row.names")
代码语言:javascript复制## TCGA-EP-A2KC-01A-11D-A20Z-05 TCGA-ES-A2HS-01A-11D-A17Z-05
## cg13938959 0.6397997 0.9317492
## cg18147296 0.8179045 0.7744908
## TCGA-ES-A2HS-11A-11D-A17Z-05 TCGA-CC-5259-01A-31D-A20Z-05
## cg13938959 0.8302542 0.4120948
## cg18147296 0.8456720 0.7253149
## TCGA-ED-A97K-01A-21D-A383-05 TCGA-DD-A3A1-01A-11D-A20Z-05
## cg13938959 0.7887094 0.8174317
## cg18147296 0.8047118 0.8544879
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: