statistics - walking through two tables (matrices) matching columns and applying a function in R -


so have 2 matrices. lets name them controls , patients. each row sample, , each column concentration of protein. looks this:

        v1    v2    v3    v4     v5     v6    v7    v8    v9     v10    v11 sample1  1533.34  9.88  6.82 17.88  70.75 350.07 20.67 13.96 10.17  711.02 114.06 sample2  2311.30 12.74  6.82 17.88  80.71 505.96 34.36 19.66 18.70  863.70 181.43 sample3  1314.83 11.39 18.12 41.26 104.36 278.17 40.25 27.12 41.34 1100.00 160.83 

this small subset, have more values. want compare matching table column. side question, correct use t-test in case, assuming data distributed? anyway. i've tried apply() function:

apply(controls,2,function(x) t.test(x, patients)$p.value) 

and getting results. have doubts if used function correctly. matches 2 columns in 2 tables meant be? or used incorrectly?

edit oh yeah. incorrect. mean value column in second table stays same.

try

 mapply(function(x,y) t.test(x,y)$p.value,           as.data.frame(controls), as.data.frame(patients))  #       v1        v2        v3        v4        v5        v6        v7        v8   #0.8481788 1.0000000 0.4605294 1.0000000 0.6436604 1.0000000    1.0000000 1.0000000   #       v9       v10       v11   #1.0000000 1.0000000 1.0000000  

assuming "controls" , "patients" matrix

data

controls <- structure(c(1253, 2311.3, 1314.83, 9.88, 12.74, 11.39,  20.8,  6.82, 18.12, 17.88, 17.88, 41.26, 70.75, 53.5, 104.36, 350.07,  505.96, 278.17, 20.67, 34.36, 40.25, 13.96, 19.66, 27.12, 10.17,  18.7, 41.34, 711.02, 863.7, 1100, 114.06, 181.43, 160.83), .dim = c(3l,  11l), .dimnames = list(c("sample1", "sample2", "sample3"), c("v1",  "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11")))  patients <- structure(c(1533.34, 2311.3, 1314.83, 9.88, 12.74, 11.39,  6.82,  6.82, 18.12, 17.88, 17.88, 41.26, 70.75, 80.71, 104.36, 350.07,  505.96, 278.17, 20.67, 34.36, 40.25, 13.96, 19.66, 27.12, 10.17,  18.7, 41.34, 711.02, 863.7, 1100, 114.06, 181.43, 160.83), .dim = c(3l,  11l), .dimnames = list(c("sample1", "sample2", "sample3"), c("v1",  "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11"))) 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

Bubble Sort Manually a Linked List in Java -

asp.net mvc - SSO between MVCForum and Umbraco7 -