Here are three options:
Option 1
Direct selection of any other element and the creation of your data.frame manually.
setNames( data.frame(unlist(poor.loci[c(TRUE, FALSE)], use.names = FALSE), unlist(poor.loci[c(FALSE, TRUE)], use.names = FALSE)), unique(names(poor.loci))) # scaf pos # 1 HE638 8 # 2 HE638 8 # 3 HE638 8
Option 2
Convert list to "long" data.frame and reshape it to the desired form. It can also be done with the "reshape2" package using melt and dcast instead of stack and reshape .
X <- stack(lapply(poor.loci, as.character)) X$ID <- ave(X$values, X$values, FUN = seq_along) reshape(X, direction = "wide", idvar="ID", timevar="ind")
Option 3
data.frame list and convert the rebuilt list to data.frame :
A <- unique(names(poor.loci)) data.frame( setNames( lapply(A, function(x) unlist(poor.loci[names(poor.loci) %in% x], use.names = FALSE)), A))
source share