Question: How to conditionally combine IntegerList in the DataFrame more elegantly?
0
gravatar for jian_liangli
2.5 years ago by
jian_liangli0 wrote:

Hi:

I used IntegerList to hold my data, and I got DataFrame in the list as an output of functions. However, I intend to combine DataFrame objects in very specific way, where firstly I am gonna combine second, third DataFrame in the list but must proceed duplicate removal, after that I am gonna combine it with first DataFrame but here I allow duplicate. I tried to use lapply functions to make this happen, but I got an error. How can I get my desired output more elegantly in function ? Any idea ?

mini example:

dfList <- list(
  DF.1 = DataFrame(hit.1=IntegerList(1,2,3), hit.2=IntegerList(NA,1,2), hit.3=IntegerList(1,1,2)),
  DF.2 = DataFrame(hit.1=IntegerList(2,3,NA), hit.2=IntegerList(1,2,3), hit.3=IntegerList(1,2,4)),
  DF.3 = DataFrame(hit.1=IntegerList(2,3,NA,NA), hit.2=IntegerList(1,2,NA,3), hit.3=IntegerList(1,2,3,4))
)

I intend to combine IntegerList with specific condition such as :

rbind(dfList[[1L]], 
      unique(rbind(dfList[[2L]], dfList[[3L]])))

but doing this way is not elegant for me, I believe there must be way to make this more elegant. How can I make this happen in functional programming more elegantly? How can I make solution more prettier that can be called in function ?Thanks in advance

> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] parallel  stats4    stats     graphics  grDevices
[6] utils     datasets  methods   base     

other attached packages:
[1] data.table_1.9.6     rtracklayer_1.34.1  
[3] GenomicRanges_1.26.1 GenomeInfoDb_1.10.0 
[5] IRanges_2.8.0        S4Vectors_0.12.0    
[7] BiocGenerics_0.20.0  BiocInstaller_1.24.0

iranges R dataframe integerlist • 486 views
ADD COMMENTlink modified 2.4 years ago by Jurat Shahidin60 • written 2.5 years ago by jian_liangli0
1

Your IntegerList are just plain integer() vectors; Do you mean perhaps

DF.1 = DataFrame(color=IntegerList(red=c(1,2,3), blue=c(NA,1,2), green=c(1,1,2)))
ADD REPLYlink modified 2.5 years ago • written 2.5 years ago by Martin Morgan ♦♦ 23k
Answer: How to conditionally combine IntegerList in the DataFrame more elegantly?
1
gravatar for Jurat Shahidin
2.4 years ago by
Italy
Jurat Shahidin60 wrote:

I believe this is the much prettier way to accomplish your task :

rbind(dfList[[1]], 
      unique(do.call("rbind", dfList[2: length(dfList)])))

cheers :)

ADD COMMENTlink written 2.4 years ago by Jurat Shahidin60
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 146 users visited in the last hour