How to conditionally combine IntegerList in the DataFrame more elegantly?
1
0
Entering edit mode
@jian_liangli-11294
Last seen 7.4 years ago

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

r iranges integerlist DataFrame • 1.1k views
ADD COMMENT
1
Entering edit mode

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 REPLY
1
Entering edit mode
@jurat-shahidin-9488
Last seen 4.1 years ago
Chicago, IL, USA

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 COMMENT

Login before adding your answer.

Traffic: 431 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6