UPDATE Using different solutions found throughout the site:
I still cannot achieve the desired output using the stack and ldply functions:
The desired output would look like this:
Dataset Samples
1 WGS nrow(WGS.ped)
2 WES nrow(WES.ped.exp)
3 MIPS nrow(MIPS.ped.exp)
1) ldply
: How to assign a name to columns V1
and .id
?
ldply(list(WGS=WGS.ped, WES=WES.ped.exp, MIPS=mips.ped.exp),
function(l)(Samples=nrow(l)))
.id V1
1 WGS 3908
2 WES 26367
3 MIPS 14193
2) ldply
: How to assign a name to columns V1
and .id
?
ldply(list(WGS=WGS.ped, WES=WES.ped.exp, MIPS=mips.ped.exp), nrow)
.id V1
1 WGS 3908
2 WES 26367
3 MIPS 14193
3) lapply %>% as.data.frame
: Returns the data frame names as columns, instead of as a first column 'Dataset
'.
lapply(list(WGS=WGS.ped, WES=WES.ped.exp, MIPS=mips.ped.exp), nrow) %>%
as.data.frame
WGS WES MIPS
1 3908 26367 14193
4) sapply %>% stack
: How to reverse the order of the columns? And how to indicate column names with stack
?
sapply(list(WGS=WGS.ped, WES=WES.ped.exp, MIPS=mips.ped.exp), nrow) %>%
stack()
values ind
1 3908 WGS
2 26367 WES
3 14193 MIPS
5) map %>% as.data.frame
: Returns the data frame names as columns, instead of as a first column 'Dataset
'.
map(list(WGS=WGS.ped, WES=WES.ped.exp, MIPS=mips.ped.exp), nrow) %>%
as.data.frame()
WGS WES MIPS
3908 26367 14193
I have three data frames WGS.ped, WES.ped,exp
and MIPS.ped.exp
.
I want to create a new data frame that summarizes their row count / the total number of rows in each data frame.
The desired output would look like this:
Dataset Samples
WGS nrow(WGS.ped)
WES nrow(WES.ped.exp)
MIPS nrow(MIPS.ped.exp)
What is an efficient and reproducible way to achieve this, preferably with dplyr?
Thanks!