I want to generate a dataframe, hminput, with 3 parameters from different smaller dataframes (named frqAFR, frqAMR, .. etc, as you can see below). So, instead of writing separately all the code to extract the three columns of each one and then bind them by column and after that by row, I was wondering if I could optimize it a bit with a for loop with strings from a list.
So, here is my idea so far:
listpop<-c("frqAFR","frqAMR","frqEUR","frqEAS","frqSAS","frqAFROURU","frqIND")
for (g in listpop) {
hminput<- rbind(cbind(paste(g)["SNP"],paste(g)["POP"],paste(g)["MAF"]))
}
But it generates a hminput dataframe with three NAs. Any thoughts? Thanks!
Desired output:
hminput
snp1 pop1 maf1
snp2 pop2 maf2
snp3 pop3 maf3
...
hminputthere inrbind. Something like ,rbind(hminput, cbind(paste(g).....?? and I am sure there are more efficient and simple way to do this.