library(reshape2);
arc_genus_2<-read.table(“arc_otu.csv”,header=TRUE,sep=”\t”);
arc_otu.csv 数据存放位置http://pan.baidu.com/s/1mgFofuK

nn<-4;
aa<-arc_genus_2[,c(2:(nn+1),(nn+7))];
md<-melt(aa,id=”genus”);
ab<-dcast(md,genus~variable,sum);

md数据:
reshape2_1

 

ab数据:reshape2_2

 

reshape2_3

 

melt(data, id.vars,measure.vars,variable.name = “variable”, …, na.rm = FALSE,value.name = “value”)
dcast(data, formula, fun.aggregate = NULL, …, margins = NULL,
subset = NULL, fill = NULL, drop = TRUE,
value.var = guess_value(data))

acast(data, formula, fun.aggregate = NULL, …, margins = NULL,
subset = NULL, fill = NULL, drop = TRUE,
value.var = guess_value(data))

参考资料:
R语言实战

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注