R: Result vector is not showing up in For Loop

OK, so I am new to R, but I've had some pretty good success so far - I am running a statistical test between corresponding rows of two dataframes (well, one is just a string of values since it has just one column). I wish to use the following For-Loop:

zvalues = NULL
zvalues = numeric(0)
for(i in seq(nrow(geneexpx))){
  zvalues[i] <- try(unname((geneexpx[i]-rowMeans(geneexpy[i,])) / rowSds(geneexpy[i,])))
}

The problem is, the resultant zvalues numeric is empty. I have no idea why. I can run the same function for a single row and it works fine. For instance:

s = unname(geneexpx[4]-rowMeans(geneexpy[4,])) / rowSds(geneexpy[4,])
s
[1] -2.431277e+156

Please let me know if you have any ideas as to what might be the problem.

EDIT: head of geneexpx:

c(1.501400411, -0.818584726, -0.455614921, -0.138022494, -1.213938495, -0.536465133)  

geneexpy is very large, but each column is similar to geneexpx above.

Answers


You have a couple things going on here. First, you need to define zvalues as a vector. Second, rowMeans and rowSds are operations on matrices, not vectors. By selecting greneecxpy[i, ] you are selecting the ith row of the matrix, which will be a vector.

You did not provide geneexpy so I made one up:

zvalues = rep(NA, length(geneexpx))
geneexpy <- matrix(runif(60), nrow = 6)
for(i in seq_along(geneexpx)){
  zvalues[i] <- (geneexpx[i] - mean(geneexpy[i,])) / sd(geneexpy[i,])
}

> zvalues
[1]  3.772994 -4.283168 -2.812811 -2.074548 -5.649359 -4.323920

Need Your Help

Using Caching with AutomationElements does not give me a speedup - intended or wrong usage?

c# ui-automation performance microsoft-ui-automation

I am trying to increase the speed of some UI Automation operations. I stumbled across the (not so well) documented caching possibility.

how can one change the default disk cache behavior in volley?

android android-volley

The service I am using to obtain images, like many such sites does not have a cache control header indicating how long the image should be cached. Volley uses an http cache control header by defaul...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.