data structures - R apply script output in different formats for similar inputs -
i'm using double apply function list of p-values cor.test between 2 columns of 2 tables.
hel_plist<-apply(bc, 2, function(x) { apply(otud, 2, function(y) { if (cor.test(x,y,method="spearman", exact=false)$p.value<0.05){cor.test(x,y,method="spearman", exact=false)$p.value}}) }) the otud data.frame 90x11 (90rows,11 colums or dim(otud) 90 11) , used different data.frames. bc , hel - both 90x2 data.frame-s - both 2*11=22 p-values out of functions
bc_plist<-apply(bc, 2, function(x) { apply(otud, 2, function(y) { if (cor.test(x,y,method="spearman", exact=false)$p.value<0.05){cor.test(x,y,method="spearman", exact=false)$p.value}}) }) hel_plist<-apply(hel, 2, function(x) { apply(otud, 2, function(y) { if (cor.test(x,y,method="spearman", exact=false)$p.value<0.05){cor.test(x,y,method="spearman", exact=false)$p.value}}) }) for bc have output dim=null list of elements of otunames$bcnames$ p-value (a format have got these scripts , happy with) hel , output of dim(hel) 11 2 - 11x2 table p-values written inside.
shortened examples of output.
hel_plist
+--------+--------------+--------------+ | | axis1 | axis2 | +--------+--------------+--------------+ | otu037 | 1.126362e-18 | 0.01158251 | | otu005 | 3.017458e-2 | null | | otu068 | 0.00476002 | null | | otu070 | 1.27646e-15 | 5.252419e-07 | +--------+--------------+--------------+ bc_plist
$axis1 $axis1$otu037 [1] 1.247717e-06 $axis1$otu005 [1] 1.990313e-05 $axis1$otu068 [1] 5.664597e-07 why when input formats same? (shortened examples)
bc
+-------+-----------+-----------+ | group | axis1 | axis2 | +-------+-----------+-----------+ | 1b041 | 0.125219 | 0.246319 | | 1b060 | -0.022412 | -0.030227 | | 1b197 | -0.088005 | -0.305351 | | 1b222 | -0.119624 | -0.144123 | | 1b227 | -0.148946 | -0.061741 | +-------+-----------+-----------+ hel
+-------+---------------+---------------+ | group | axis1 | axis2 | +-------+---------------+---------------+ | 1b041 | -0.0667782322 | -0.1660606406 | | 1b060 | 0.0214470932 | -0.0611351008 | | 1b197 | 0.1761876858 | 0.0927570627 | | 1b222 | 0.0681058251 | 0.0549292399 | | 1b227 | 0.0516864361 | 0.0774155225 | | 1b235 | 0.1205676221 | 0.0181712761 | +-------+---------------+---------------+ how force scripts produce "flat" outputs in case of bc
ok different output-s caused because of null results conditional function in bc_plist case. if i'd modify code replace possible null-s na-s i'd 2d tables in case. keep things constant :
bc_nmds_plist<-apply(bc_nmds, 2, function(x) { apply(stoma_otud, 2, function(y) { if (cor.test(x,y,method="spearman", exact=false)$p.value<0.05){cor.test(x,y,method="spearman", exact=false)$p.value}else na}) }) and 2d tabel out bc_nmds_plist too. guess thing can called solved - have piece of code produces predictable output on correct input. if has idea how force output conform previos bc_plist format instead still interested prefer form:
$axis1 $axis1$otu037 [1] 1.247717e-06 $axis1$otu005 [1] 1.990313e-05 $axis1$otu068 [1] 5.664597e-07
Comments
Post a Comment