Shuhua Zhan
2015-Jan-19 20:14 UTC
[R] add a list name into the list content in a new output
Dear All, I'd like to add a list name into the list contents to make a new output. The list is a list of data.frame derived from summary command in Rqtl. I want to add this list name to the data frame with a given column name such as "trait" and output this entire list as a table tab delimited as below. Here is the list generated by summary command in Rqtl:> summary(out.all, threshold=3, format="tabByCol")bp: chr pos ci.low ci.high lod c7.loc45 7 47.7 36.71 56.7 6.11 c15.loc8 15 12.0 3.96 22.8 5.29 hr: chr pos ci.low ci.high lod c2.loc54 2 59.8 14.8 87.8 4.19 D15MIT184 15 22.8 12.0 36.0 3.15 bw: chr pos ci.low ci.high lod c15.loc16 15 20 11 30 6.75 heart_wt: chr pos ci.low ci.high lod c12.loc49 12 51.2 28.2 62.2 3.65 The new output I want: trait locus chr pos ci.low ci.high lod bp c7.loc45 7 47.7 36.71 56.7 6.11 bp c15.loc8 15 12.0 3.96 22.8 5.29 trait locus chr pos ci.low ci.high lod hr c2.loc54 2 59.8 14.8 87.8 4.19 hr D15MIT184 15 22.8 12.0 36.0 3.15 trait locus chr pos ci.low ci.high lod bw c15.loc16 15 20 11 30 6.75 heart_wt locus chr pos ci.low ci.high lod trait c12.loc49 12 51.2 28.2 62.2 3.65 I appreciate for your help for any suggestions!! Joshua
Chel Hee Lee
2015-Jan-20 03:44 UTC
[R] add a list name into the list content in a new output
I am just using the first two components of your output. > op $bp chr pos ci.low ci.high lod c7.loc45 7 47.7 36.71 56.7 6.11 c15.loc8 15 12.0 3.96 22.8 5.29 $hr chr pos ci.low ci.high lod c2.loc54 2 59.8 14.8 87.8 4.19 D15MIT184 15 22.8 12.0 36.0 3.15 > > result <- lapply(names(op), function(x){ + col1 <- x + col2 <- row.names(op[[x]]) + mat <- op[[x]] + row.names(mat) <- NULL + rval <- cbind(col1, col2, mat) + names(rval) <- c("trait", "locus", names(mat)) + rval + }) > > result [[1]] trait locus chr pos ci.low ci.high lod 1 bp c7.loc45 7 47.7 36.71 56.7 6.11 2 bp c15.loc8 15 12.0 3.96 22.8 5.29 [[2]] trait locus chr pos ci.low ci.high lod 1 hr c2.loc54 2 59.8 14.8 87.8 4.19 2 hr D15MIT184 15 22.8 12.0 36.0 3.15 > Is this what you are looking for? I hope this helps. Chel Hee Lee On 01/19/2015 02:14 PM, Shuhua Zhan wrote:> Dear All, > I'd like to add a list name into the list contents to make a new output. The list is a list of data.frame derived from summary command in Rqtl. I want to add this list name to the data frame with a given column name such as "trait" and output this entire list as a table tab delimited as below. > Here is the list generated by summary command in Rqtl: >> summary(out.all, threshold=3, format="tabByCol") > bp: > chr pos ci.low ci.high lod > c7.loc45 7 47.7 36.71 56.7 6.11 > c15.loc8 15 12.0 3.96 22.8 5.29 > > hr: > chr pos ci.low ci.high lod > c2.loc54 2 59.8 14.8 87.8 4.19 > D15MIT184 15 22.8 12.0 36.0 3.15 > > bw: > chr pos ci.low ci.high lod > c15.loc16 15 20 11 30 6.75 > > heart_wt: > chr pos ci.low ci.high lod > c12.loc49 12 51.2 28.2 62.2 3.65 > > > The new output I want: > > trait locus chr pos ci.low ci.high lod > bp c7.loc45 7 47.7 36.71 56.7 6.11 > bp c15.loc8 15 12.0 3.96 22.8 5.29 > > trait locus chr pos ci.low ci.high lod > hr c2.loc54 2 59.8 14.8 87.8 4.19 > hr D15MIT184 15 22.8 12.0 36.0 3.15 > > trait locus chr pos ci.low ci.high lod > bw c15.loc16 15 20 11 30 6.75 > > heart_wt locus chr pos ci.low ci.high lod > trait c12.loc49 12 51.2 28.2 62.2 3.65 > > I appreciate for your help for any suggestions!! > Joshua > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >