【3.3】reshape2包--数据变形

示例:

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语言实战

个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn

Sam avatar
About Sam
专注生物信息 专注转化医学