Hi guys,
why with this two kinds of code the results are different?
ego.matrix <- t(apply(ego.matrix, 1, function(x){
gene <- x["gene"]
out <- coeff.clustering(nt_graph, gene)
out2 <- coeff.clustering(nt2_graph, gene)
out3 <- coeff.clustering(nt3_graph, gene)
return(c(gene, out, out2, out3))
}))
colnames(ego.matrix)[2] <- "tcga.controls"
colnames(ego.matrix)[3] <- "tcga.tumors"
colnames(ego.matrix)[4] <- "gtex.brca"
the execution of this code with the apply is only to replace the NA value of the empty dataframe with the clustering coefficient... I made this type of code also with the foor loop for seeing the difference in computational terms...
for(idx in rownames(ego.matrix)) {
ego.matrix[as.numeric(idx), "tcga.controls"] <- coeff.clustering(nt_graph, ego.matrix[as.numeric(idx), "gene"])
ego.matrix[as.numeric(idx), "tcga.tumors"] <- coeff.clustering(nt2_graph, ego.matrix[as.numeric(idx), "gene"])
ego.matrix[as.numeric(idx), "gtex.brca"] <- coeff.clustering(nt3_graph, ego.matrix[as.numeric(idx), "gene"])
}
... But, in this case the result was pretty different few rows changed the values..... why? (this solution is correct in terms of results, not in the case of the apply mode...
Another difference is.... the type of variable; with the apply the variable ego.matrix was a character.... instead, with the foor loop a list.... WHY?
.. meanwhile, Happy Easter to everyone
Kind regards,
JS