[Bioc-devel] DataFrameList to Wide Format DataFrame
Dario Strbenac
d@tr7320 @end|ng |rom un|@@ydney@edu@@u
Fri Dec 17 08:00:11 CET 2021
Hello,
Ah, yes, the sample names should of course be in the rows - Friday afternoon error. In the question, I specified "largely the same set of features", implying that the overlap is not complete. So, the example below will error.
DFL <- DataFrameList(X = DataFrame(a = 1:3, b = 3:1, row.names = LETTERS[1:3]),
Y = DataFrame(b = 4:6, c = 6:4, row.names = LETTERS[20:22]))
unlist(DFL)
Error in .aggregate_and_align_all_colnames(all_colnames, strict.colnames = strict.colnames) :
the DFrame objects to combine must have the same column names
This is long but works:
allFeatures <- unique(unlist(lapply(DFL, colnames)))
DFL <- lapply(DFL, function(DF)
{
missingFeatures <- setdiff(allFeatures, colnames(DF))
DF[missingFeatures] <- NA
DF
})
DFLflattened <- do.call(rbind, DFL)
Is there a one-line function for it?
--------------------------------------
Dario Strbenac
University of Sydney
Camperdown NSW 2050
Australia
More information about the Bioc-devel
mailing list