about transforming a data.frame
2
0
Entering edit mode
Bogdan ▴ 670
@bogdan-2367
Last seen 6 months ago
Palo Alto, CA, USA

Dear all,
 

I would appreciate a suggestion on the following : I am working with a data.frame (below) :

  EXP    CT   row_names   col_names                 
1   test -5    B4:B5:B6    B1:B2:B3              
2   test -2    B7:B8:B9    B1:B2:B3              
3   test -2    D4:D5:D6    H4:H5:H6              
4   test -2    D10:D11:D12 F10:F11:F12             
5   test -2    D10:D11:D12    H1:H2:H3              
6   test -2    E10:E11:E12    G7:G8:G9             
7   test -4     A1:A2:A3    D1:D2:D3                
8   test -4   B10:B11:B12    B1:B2:B3              

what would be the easiest way to consider UNIQUE elements in the ROW_NAMES or the UNIQUE elements in the COL_NAMES and :

print how many times these UNIQUE ELEMENTS associate with the numbers -5, -2, or -4 (these numbers are on the column names CT) ..

thanks,

bogdan

data • 1.2k views
ADD COMMENT
1
Entering edit mode
@steve-lianoglou-2771
Last seen 13 months ago
United States

This is really an R question as opposed to a Bioconductor question, but I'll play a little code golf.

Not sure that I understand what you want, actually, but here is one way to get the result that I think you are after using data.table:

x <- read.table(textConnection("
  EXP    CT   row_names   col_names                 
1   test -5    B4:B5:B6    B1:B2:B3              
2   test -2    B7:B8:B9    B1:B2:B3              
3   test -2    D4:D5:D6    H4:H5:H6              
4   test -2    D10:D11:D12 F10:F11:F12             
5   test -2    D10:D11:D12    H1:H2:H3              
6   test -2    E10:E11:E12    G7:G8:G9             
7   test -4     A1:A2:A3    D1:D2:D3                
8   test -4   B10:B11:B12    B1:B2:B3              
"))

x <- transform(as.data.table(x), CT=factor(CT))
x[, as.list(table(CT)), by='row_names']

##         row_names -5 -4 -2
##    1:    B4:B5:B6  1  0  0
##    2:    B7:B8:B9  0  0  1
##    3:    D4:D5:D6  0  0  1
##    4: D10:D11:D12  0  0  2
##    5: E10:E11:E12  0  0  1
##    6:    A1:A2:A3  0  1  0
##    7: B10:B11:B12  0  1  0

I would provide the "competing" dplyr code, but I'm not exactly sure what the idiomatic dplyr way to do that is.

 

ADD COMMENT
0
Entering edit mode
Bogdan ▴ 670
@bogdan-2367
Last seen 6 months ago
Palo Alto, CA, USA

Thanks Steve, it helps a lot !

ADD COMMENT

Login before adding your answer.

Traffic: 810 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