[英]How to transpose data frame , keeping row and column names using R
I have a gene expression dataset that currently has columns of patient samples and rows of genes. 我有一个基因表达数据集,当前有患者样本列和基因行。 I need to transpose the dataset so that the genes are now columns and rows are now patient samples using R. I have found a few ways yet none have been successful. 我需要转置数据集,以使基因现在成为使用R的列和行成为患者样本。我发现了几种方法,但都没有成功。 I appreciate your help in advance! 感谢您的帮助! :) :)
Make a data frame as follows: 制作如下数据框:
df <- data.frame(Joe = c(45,123,1007), Mary=c(1,456,103))
rownames(df) <- c("Wnt1", "Bmp4", "BRCA2")
df
Joe Mary
Wnt1 45 1
Bmp4 123 456
BRCA2 1007 103
And to transpose it, simply: 并转置它,只需:
t(df)
Wnt1 Bmp4 BRCA2
Joe 45 123 1007
Mary 1 456 103
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.