[R] From list to dataframe
Hello, having a list like testlist I would like to transform it in dataframe. How does it work? Thanks Hermann testlist [[1]] BP_A SNP_A BP_B SNP_B R2 2 27001689 rs4822747 27002392 rs4820690 0.695642 3 27001689 rs4822747 27004298 rs5761627 0.695642 4 27001689 rs4822747 27004902 rs5752355 0.687861 5 27001689 rs4822747 27004964 rs4822748 0.682715 6 27001689 rs4822747 27005122 rs4820691 0.695642 7 27001689 rs4822747 27005158 rs4822749 0.695642 [[2]] BP_A SNP_A BP_B SNP_B R2 9 27002392 rs4820690 27001689 rs4822747 0.695642 11 27002392 rs4820690 27004298 rs5761627 1.00 12 27002392 rs4820690 27004902 rs5752355 0.988681 13 27002392 rs4820690 27004964 rs4822748 0.988655 14 27002392 rs4820690 27005122 rs4820691 1.00 15 27002392 rs4820690 27005158 rs4822749 1.00 16 27002392 rs4820690 27005194 rs4822750 0.988655 17 27002392 rs4820690 27005470 rs5761629 0.695642 [[3]] BP_A SNP_A BP_B SNP_B R2 19 27004298 rs5761627 27001689 rs4822747 0.695642 20 27004298 rs5761627 27002392 rs4820690 1.00 22 27004298 rs5761627 27004902 rs5752355 0.988681 23 27004298 rs5761627 27004964 rs4822748 0.988655 24 27004298 rs5761627 27005122 rs4820691 1.00 25 27004298 rs5761627 27005158 rs4822749 1.00 #The aim is the dataframe BP_A SNP_A BP_B SNP_B R2 2 27001689 rs4822747 27002392 rs4820690 0.695642 3 27001689 rs4822747 27004298 rs5761627 0.695642 4 27001689 rs4822747 27004902 rs5752355 0.687861 5 27001689 rs4822747 27004964 rs4822748 0.682715 6 27001689 rs4822747 27005122 rs4820691 0.695642 7 27001689 rs4822747 27005158 rs4822749 0.695642 9 27002392 rs4820690 27001689 rs4822747 0.695642 11 27002392 rs4820690 27004298 rs5761627 1.00 12 27002392 rs4820690 27004902 rs5752355 0.988681 13 27002392 rs4820690 27004964 rs4822748 0.988655 14 27002392 rs4820690 27005122 rs4820691 1.00 15 27002392 rs4820690 27005158 rs4822749 1.00 16 27002392 rs4820690 27005194 rs4822750 0.988655 17 27002392 rs4820690 27005470 rs5761629 0.695642 19 27004298 rs5761627 27001689 rs4822747 0.695642 20 27004298 rs5761627 27002392 rs4820690 1.00 22 27004298 rs5761627 27004902 rs5752355 0.988681 23 27004298 rs5761627 27004964 rs4822748 0.988655 24 27004298 rs5761627 27005122 rs4820691 1.00 25 27004298 rs5761627 27005158 rs4822749 1.00 dput (testlist) list(structure(list(BP_A = c(27001689L, 27001689L, 27001689L, 27001689L, 27001689L, 27001689L), SNP_A = c(rs4822747, rs4822747, rs4822747, rs4822747, rs4822747, rs4822747), BP_B = c(27002392L, 27004298L, 27004902L, 27004964L, 27005122L, 27005158L), SNP_B = c(rs4820690, rs5761627, rs5752355, rs4822748, rs4820691, rs4822749 ), R2 = c(0.695642, 0.695642, 0.687861, 0.682715, 0.695642, 0.695642 )), .Names = c(BP_A, SNP_A, BP_B, SNP_B, R2), row.names = 2:7, class = data.frame), structure(list(BP_A = c(27002392L, 27002392L, 27002392L, 27002392L, 27002392L, 27002392L, 27002392L, 27002392L), SNP_A = c(rs4820690, rs4820690, rs4820690, rs4820690, rs4820690, rs4820690, rs4820690, rs4820690), BP_B = c(27001689L, 27004298L, 27004902L, 27004964L, 27005122L, 27005158L, 27005194L, 27005470L ), SNP_B = c(rs4822747, rs5761627, rs5752355, rs4822748, rs4820691, rs4822749, rs4822750, rs5761629), R2 = c(0.695642, 1, 0.988681, 0.988655, 1, 1, 0.988655, 0.695642)), .Names = c(BP_A, SNP_A, BP_B, SNP_B, R2), row.names = c(9L, 11L, 12L, 13L, 14L, 15L, 16L, 17L), class = data.frame), structure(list( BP_A = c(27004298L, 27004298L, 27004298L, 27004298L, 27004298L, 27004298L), SNP_A = c(rs5761627, rs5761627, rs5761627, rs5761627, rs5761627, rs5761627), BP_B = c(27001689L, 27002392L, 27004902L, 27004964L, 27005122L, 27005158L), SNP_B = c(rs4822747, rs4820690, rs5752355, rs4822748, rs4820691, rs4822749), R2 = c(0.695642, 1, 0.988681, 0.988655, 1, 1)), .Names = c(BP_A, SNP_A, BP_B, SNP_B, R2), row.names = c(19L, 20L, 22L, 23L, 24L, 25L), class = data.frame)) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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.
Re: [R] From list to dataframe
Hi. Here is one way: l - list(structure(list(BP_A = c(27001689L, 27001689L, 27001689L, 27001689L, 27001689L, 27001689L), SNP_A = c(rs4822747, rs4822747, rs4822747, rs4822747, rs4822747, rs4822747), BP_B = c(27002392L, 27004298L, 27004902L, 27004964L, 27005122L, 27005158L), SNP_B = c(rs4820690, rs5761627, rs5752355, rs4822748, rs4820691, rs4822749 ), R2 = c(0.695642, 0.695642, 0.687861, 0.682715, 0.695642, 0.695642 )), .Names = c(BP_A, SNP_A, BP_B, SNP_B, R2), row.names = 2:7, class = data.frame), structure(list(BP_A = c(27002392L, 27002392L, 27002392L, 27002392L, 27002392L, 27002392L, 27002392L, 27002392L), SNP_A = c(rs4820690, rs4820690, rs4820690, rs4820690, rs4820690, rs4820690, rs4820690, rs4820690), BP_B = c(27001689L, 27004298L, 27004902L, 27004964L, 27005122L, 27005158L, 27005194L, 27005470L ), SNP_B = c(rs4822747, rs5761627, rs5752355, rs4822748, rs4820691, rs4822749, rs4822750, rs5761629), R2 = c(0.695642, 1, 0.988681, 0.988655, 1, 1, 0.988655, 0.695642)), .Names = c(BP_A, SNP_A, BP_B, SNP_B, R2), row.names = c(9L, 11L, 12L, 13L, 14L, 15L, 16L, 17L), class = data.frame), structure(list( BP_A = c(27004298L, 27004298L, 27004298L, 27004298L, 27004298L, 27004298L), SNP_A = c(rs5761627, rs5761627, rs5761627, rs5761627, rs5761627, rs5761627), BP_B = c(27001689L, 27002392L, 27004902L, 27004964L, 27005122L, 27005158L), SNP_B = c(rs4822747, rs4820690, rs5752355, rs4822748, rs4820691, rs4822749), R2 = c(0.695642, 1, 0.988681, 0.988655, 1, 1)), .Names = c(BP_A, SNP_A, BP_B, SNP_B, R2), row.names = c(19L, 20L, 22L, 23L, 24L, 25L), class = data.frame)) do.call(rbind, l) Andrija On Thu, Nov 14, 2013 at 9:41 AM, Hermann Norpois hnorp...@gmail.com wrote: Hello, having a list like testlist I would like to transform it in dataframe. How does it work? Thanks Hermann testlist [[1]] BP_A SNP_A BP_B SNP_B R2 2 27001689 rs4822747 27002392 rs4820690 0.695642 3 27001689 rs4822747 27004298 rs5761627 0.695642 4 27001689 rs4822747 27004902 rs5752355 0.687861 5 27001689 rs4822747 27004964 rs4822748 0.682715 6 27001689 rs4822747 27005122 rs4820691 0.695642 7 27001689 rs4822747 27005158 rs4822749 0.695642 [[2]] BP_A SNP_A BP_B SNP_B R2 9 27002392 rs4820690 27001689 rs4822747 0.695642 11 27002392 rs4820690 27004298 rs5761627 1.00 12 27002392 rs4820690 27004902 rs5752355 0.988681 13 27002392 rs4820690 27004964 rs4822748 0.988655 14 27002392 rs4820690 27005122 rs4820691 1.00 15 27002392 rs4820690 27005158 rs4822749 1.00 16 27002392 rs4820690 27005194 rs4822750 0.988655 17 27002392 rs4820690 27005470 rs5761629 0.695642 [[3]] BP_A SNP_A BP_B SNP_B R2 19 27004298 rs5761627 27001689 rs4822747 0.695642 20 27004298 rs5761627 27002392 rs4820690 1.00 22 27004298 rs5761627 27004902 rs5752355 0.988681 23 27004298 rs5761627 27004964 rs4822748 0.988655 24 27004298 rs5761627 27005122 rs4820691 1.00 25 27004298 rs5761627 27005158 rs4822749 1.00 #The aim is the dataframe BP_A SNP_A BP_B SNP_B R2 2 27001689 rs4822747 27002392 rs4820690 0.695642 3 27001689 rs4822747 27004298 rs5761627 0.695642 4 27001689 rs4822747 27004902 rs5752355 0.687861 5 27001689 rs4822747 27004964 rs4822748 0.682715 6 27001689 rs4822747 27005122 rs4820691 0.695642 7 27001689 rs4822747 27005158 rs4822749 0.695642 9 27002392 rs4820690 27001689 rs4822747 0.695642 11 27002392 rs4820690 27004298 rs5761627 1.00 12 27002392 rs4820690 27004902 rs5752355 0.988681 13 27002392 rs4820690 27004964 rs4822748 0.988655 14 27002392 rs4820690 27005122 rs4820691 1.00 15 27002392 rs4820690 27005158 rs4822749 1.00 16 27002392 rs4820690 27005194 rs4822750 0.988655 17 27002392 rs4820690 27005470 rs5761629 0.695642 19 27004298 rs5761627 27001689 rs4822747 0.695642 20 27004298 rs5761627 27002392 rs4820690 1.00 22 27004298 rs5761627 27004902 rs5752355 0.988681 23 27004298 rs5761627 27004964 rs4822748 0.988655 24 27004298 rs5761627 27005122 rs4820691 1.00 25 27004298 rs5761627 27005158 rs4822749 1.00 dput (testlist) list(structure(list(BP_A = c(27001689L, 27001689L, 27001689L, 27001689L, 27001689L, 27001689L), SNP_A = c(rs4822747, rs4822747, rs4822747, rs4822747, rs4822747, rs4822747), BP_B = c(27002392L, 27004298L, 27004902L, 27004964L, 27005122L, 27005158L), SNP_B = c(rs4820690, rs5761627, rs5752355, rs4822748, rs4820691, rs4822749 ), R2 = c(0.695642, 0.695642, 0.687861, 0.682715, 0.695642, 0.695642 )), .Names = c(BP_A, SNP_A, BP_B, SNP_B, R2), row.names = 2:7, class = data.frame), structure(list(BP_A = c(27002392L, 27002392L, 27002392L, 27002392L, 27002392L, 27002392L, 27002392L, 27002392L), SNP_A = c(rs4820690, rs4820690, rs4820690, rs4820690, rs4820690, rs4820690, rs4820690, rs4820690), BP_B = c(27001689L, 27004298L, 27004902L,
Re: [R] From list to dataframe
Hi Hermann, You may try: do.call(rbind,testlist) #or Reduce(rbind,testlist) #or library(plyr) ldply(testlist) A.K. On Thursday, November 14, 2013 8:27 AM, Hermann Norpois hnorp...@gmail.com wrote: Hello, having a list like testlist I would like to transform it in dataframe. How does it work? Thanks Hermann testlist [[1]] BP_A SNP_A BP_B SNP_B R2 2 27001689 rs4822747 27002392 rs4820690 0.695642 3 27001689 rs4822747 27004298 rs5761627 0.695642 4 27001689 rs4822747 27004902 rs5752355 0.687861 5 27001689 rs4822747 27004964 rs4822748 0.682715 6 27001689 rs4822747 27005122 rs4820691 0.695642 7 27001689 rs4822747 27005158 rs4822749 0.695642 [[2]] BP_A SNP_A BP_B SNP_B R2 9 27002392 rs4820690 27001689 rs4822747 0.695642 11 27002392 rs4820690 27004298 rs5761627 1.00 12 27002392 rs4820690 27004902 rs5752355 0.988681 13 27002392 rs4820690 27004964 rs4822748 0.988655 14 27002392 rs4820690 27005122 rs4820691 1.00 15 27002392 rs4820690 27005158 rs4822749 1.00 16 27002392 rs4820690 27005194 rs4822750 0.988655 17 27002392 rs4820690 27005470 rs5761629 0.695642 [[3]] BP_A SNP_A BP_B SNP_B R2 19 27004298 rs5761627 27001689 rs4822747 0.695642 20 27004298 rs5761627 27002392 rs4820690 1.00 22 27004298 rs5761627 27004902 rs5752355 0.988681 23 27004298 rs5761627 27004964 rs4822748 0.988655 24 27004298 rs5761627 27005122 rs4820691 1.00 25 27004298 rs5761627 27005158 rs4822749 1.00 #The aim is the dataframe BP_A SNP_A BP_B SNP_B R2 2 27001689 rs4822747 27002392 rs4820690 0.695642 3 27001689 rs4822747 27004298 rs5761627 0.695642 4 27001689 rs4822747 27004902 rs5752355 0.687861 5 27001689 rs4822747 27004964 rs4822748 0.682715 6 27001689 rs4822747 27005122 rs4820691 0.695642 7 27001689 rs4822747 27005158 rs4822749 0.695642 9 27002392 rs4820690 27001689 rs4822747 0.695642 11 27002392 rs4820690 27004298 rs5761627 1.00 12 27002392 rs4820690 27004902 rs5752355 0.988681 13 27002392 rs4820690 27004964 rs4822748 0.988655 14 27002392 rs4820690 27005122 rs4820691 1.00 15 27002392 rs4820690 27005158 rs4822749 1.00 16 27002392 rs4820690 27005194 rs4822750 0.988655 17 27002392 rs4820690 27005470 rs5761629 0.695642 19 27004298 rs5761627 27001689 rs4822747 0.695642 20 27004298 rs5761627 27002392 rs4820690 1.00 22 27004298 rs5761627 27004902 rs5752355 0.988681 23 27004298 rs5761627 27004964 rs4822748 0.988655 24 27004298 rs5761627 27005122 rs4820691 1.00 25 27004298 rs5761627 27005158 rs4822749 1.00 dput (testlist) list(structure(list(BP_A = c(27001689L, 27001689L, 27001689L, 27001689L, 27001689L, 27001689L), SNP_A = c(rs4822747, rs4822747, rs4822747, rs4822747, rs4822747, rs4822747), BP_B = c(27002392L, 27004298L, 27004902L, 27004964L, 27005122L, 27005158L), SNP_B = c(rs4820690, rs5761627, rs5752355, rs4822748, rs4820691, rs4822749 ), R2 = c(0.695642, 0.695642, 0.687861, 0.682715, 0.695642, 0.695642 )), .Names = c(BP_A, SNP_A, BP_B, SNP_B, R2), row.names = 2:7, class = data.frame), structure(list(BP_A = c(27002392L, 27002392L, 27002392L, 27002392L, 27002392L, 27002392L, 27002392L, 27002392L), SNP_A = c(rs4820690, rs4820690, rs4820690, rs4820690, rs4820690, rs4820690, rs4820690, rs4820690), BP_B = c(27001689L, 27004298L, 27004902L, 27004964L, 27005122L, 27005158L, 27005194L, 27005470L ), SNP_B = c(rs4822747, rs5761627, rs5752355, rs4822748, rs4820691, rs4822749, rs4822750, rs5761629), R2 = c(0.695642, 1, 0.988681, 0.988655, 1, 1, 0.988655, 0.695642)), .Names = c(BP_A, SNP_A, BP_B, SNP_B, R2), row.names = c(9L, 11L, 12L, 13L, 14L, 15L, 16L, 17L), class = data.frame), structure(list( BP_A = c(27004298L, 27004298L, 27004298L, 27004298L, 27004298L, 27004298L), SNP_A = c(rs5761627, rs5761627, rs5761627, rs5761627, rs5761627, rs5761627), BP_B = c(27001689L, 27002392L, 27004902L, 27004964L, 27005122L, 27005158L), SNP_B = c(rs4822747, rs4820690, rs5752355, rs4822748, rs4820691, rs4822749), R2 = c(0.695642, 1, 0.988681, 0.988655, 1, 1)), .Names = c(BP_A, SNP_A, BP_B, SNP_B, R2), row.names = c(19L, 20L, 22L, 23L, 24L, 25L), class = data.frame)) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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. __ R-help@r-project.org mailing list 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.
Re: [R] From list to dataframe
do.call (rbind, testlist) and Reduce (rbind, testlist) are perfect. Thanks hermann 2013/11/14 arun smartpink...@yahoo.com Hi Hermann, You may try: do.call(rbind,testlist) #or Reduce(rbind,testlist) #or library(plyr) ldply(testlist) A.K. On Thursday, November 14, 2013 8:27 AM, Hermann Norpois hnorp...@gmail.com wrote: Hello, having a list like testlist I would like to transform it in dataframe. How does it work? Thanks Hermann testlist [[1]] BP_A SNP_A BP_B SNP_B R2 2 27001689 rs4822747 27002392 rs4820690 0.695642 3 27001689 rs4822747 27004298 rs5761627 0.695642 4 27001689 rs4822747 27004902 rs5752355 0.687861 5 27001689 rs4822747 27004964 rs4822748 0.682715 6 27001689 rs4822747 27005122 rs4820691 0.695642 7 27001689 rs4822747 27005158 rs4822749 0.695642 [[2]] BP_A SNP_A BP_B SNP_B R2 9 27002392 rs4820690 27001689 rs4822747 0.695642 11 27002392 rs4820690 27004298 rs5761627 1.00 12 27002392 rs4820690 27004902 rs5752355 0.988681 13 27002392 rs4820690 27004964 rs4822748 0.988655 14 27002392 rs4820690 27005122 rs4820691 1.00 15 27002392 rs4820690 27005158 rs4822749 1.00 16 27002392 rs4820690 27005194 rs4822750 0.988655 17 27002392 rs4820690 27005470 rs5761629 0.695642 [[3]] BP_A SNP_A BP_B SNP_B R2 19 27004298 rs5761627 27001689 rs4822747 0.695642 20 27004298 rs5761627 27002392 rs4820690 1.00 22 27004298 rs5761627 27004902 rs5752355 0.988681 23 27004298 rs5761627 27004964 rs4822748 0.988655 24 27004298 rs5761627 27005122 rs4820691 1.00 25 27004298 rs5761627 27005158 rs4822749 1.00 #The aim is the dataframe BP_A SNP_A BP_B SNP_B R2 2 27001689 rs4822747 27002392 rs4820690 0.695642 3 27001689 rs4822747 27004298 rs5761627 0.695642 4 27001689 rs4822747 27004902 rs5752355 0.687861 5 27001689 rs4822747 27004964 rs4822748 0.682715 6 27001689 rs4822747 27005122 rs4820691 0.695642 7 27001689 rs4822747 27005158 rs4822749 0.695642 9 27002392 rs4820690 27001689 rs4822747 0.695642 11 27002392 rs4820690 27004298 rs5761627 1.00 12 27002392 rs4820690 27004902 rs5752355 0.988681 13 27002392 rs4820690 27004964 rs4822748 0.988655 14 27002392 rs4820690 27005122 rs4820691 1.00 15 27002392 rs4820690 27005158 rs4822749 1.00 16 27002392 rs4820690 27005194 rs4822750 0.988655 17 27002392 rs4820690 27005470 rs5761629 0.695642 19 27004298 rs5761627 27001689 rs4822747 0.695642 20 27004298 rs5761627 27002392 rs4820690 1.00 22 27004298 rs5761627 27004902 rs5752355 0.988681 23 27004298 rs5761627 27004964 rs4822748 0.988655 24 27004298 rs5761627 27005122 rs4820691 1.00 25 27004298 rs5761627 27005158 rs4822749 1.00 dput (testlist) list(structure(list(BP_A = c(27001689L, 27001689L, 27001689L, 27001689L, 27001689L, 27001689L), SNP_A = c(rs4822747, rs4822747, rs4822747, rs4822747, rs4822747, rs4822747), BP_B = c(27002392L, 27004298L, 27004902L, 27004964L, 27005122L, 27005158L), SNP_B = c(rs4820690, rs5761627, rs5752355, rs4822748, rs4820691, rs4822749 ), R2 = c(0.695642, 0.695642, 0.687861, 0.682715, 0.695642, 0.695642 )), .Names = c(BP_A, SNP_A, BP_B, SNP_B, R2), row.names = 2:7, class = data.frame), structure(list(BP_A = c(27002392L, 27002392L, 27002392L, 27002392L, 27002392L, 27002392L, 27002392L, 27002392L), SNP_A = c(rs4820690, rs4820690, rs4820690, rs4820690, rs4820690, rs4820690, rs4820690, rs4820690), BP_B = c(27001689L, 27004298L, 27004902L, 27004964L, 27005122L, 27005158L, 27005194L, 27005470L ), SNP_B = c(rs4822747, rs5761627, rs5752355, rs4822748, rs4820691, rs4822749, rs4822750, rs5761629), R2 = c(0.695642, 1, 0.988681, 0.988655, 1, 1, 0.988655, 0.695642)), .Names = c(BP_A, SNP_A, BP_B, SNP_B, R2), row.names = c(9L, 11L, 12L, 13L, 14L, 15L, 16L, 17L), class = data.frame), structure(list( BP_A = c(27004298L, 27004298L, 27004298L, 27004298L, 27004298L, 27004298L), SNP_A = c(rs5761627, rs5761627, rs5761627, rs5761627, rs5761627, rs5761627), BP_B = c(27001689L, 27002392L, 27004902L, 27004964L, 27005122L, 27005158L), SNP_B = c(rs4822747, rs4820690, rs5752355, rs4822748, rs4820691, rs4822749), R2 = c(0.695642, 1, 0.988681, 0.988655, 1, 1)), .Names = c(BP_A, SNP_A, BP_B, SNP_B, R2), row.names = c(19L, 20L, 22L, 23L, 24L, 25L), class = data.frame)) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide