I am subsetting some data frames and am sure there is a better way.
Essentially, I have two data frames. The first is the actual data. The second has some meta data and importantly a flag on whether or not the row is in the subset I am interested in. All I would like to do is pull out the subset and write a file.
For instance, here is my subset data frame:
head(temp[,c(1,4:8)])
ensembl_gene_id FGF Secreted SigP Receptors TF
1 ENSMUSG00000000001 FALSE FALSE FALSE TRUE FALSE
2 ENSMUSG00000000001 FALSE FALSE FALSE TRUE FALSE
3 ENSMUSG00000000001 FALSE FALSE FALSE TRUE FALSE
4 ENSMUSG00000000001 FALSE FALSE FALSE TRUE FALSE
5 ENSMUSG00000000001 FALSE FALSE FALSE TRUE FALSE
6 ENSMUSG00000000001 FALSE FALSE FALSE TRUE FALSE
Here is my actual data:
Expt1_C1_EXONS_dxd_res_wDesc[1:5,1:5]
groupID featureID exonBaseMean dispersion stat
ENSMUSG00000000001:E001 ENSMUSG00000000001 E001 624.80240 0.04271781 1.255734504
ENSMUSG00000000001:E002 ENSMUSG00000000001 E002 30.92281 0.02036015 0.514038911
ENSMUSG00000000001:E003 ENSMUSG00000000001 E003 41.61413 0.01546023 10.105615831
ENSMUSG00000000001:E004 ENSMUSG00000000001 E004 137.47209 0.03975305 0.281105120
ENSMUSG00000000001:E005 ENSMUSG00000000001 E005 85.97116 0.05753662 0.005482149`
What I was doing is:
write.table(Expt1_C1_EXONS_dxd_res_wDesc[temp$FGF,],
"Expt1_C1_EXONS_dxd_res_wDesc_FGF.tab",col.names=T,row.names=F,quote=F)
This is taking 20+ min per subset just to subset and write the data. The data frame is 370,000 rows by 27 variables, so large but not huge. I have about 30 of these to do. Is there a more efficient way? Note, the groupID does NOT equal the first column in my subset data frame. In some instances the groupID contains a concatenated set of ensembl ids. So I have preprocessed to get the temp data frame to have what I want in the same row order.
Thanks, Bob
Expt1_C1_EXONS_dxd_res_wDesc[temp$FGF,]
was not doing what I intended. I had thought it would interpret the T/F in that column in the data frame temp and use that as inclusion/exclusion criteria. Changing that toExpt1_C1_EXONS_dxd_res_wDesc[temp$FGF=="TRUE",]
works and takes almost no time. Examining the results of the incorrect version, it produced a huge file with all NA's. So my question is now, why didn't it take my temp$FGF values and what was it actually doing in that case? Thanks $\endgroup$