Skip to content
Prev 352348 / 398500 Next

question

Hi Ati,
Let's start from the top and see where we finish up. I'll use a
somewhat smaller matrix:

met<-matrix(runif(5),ncol=1)
rownames(met)<-c("glycine_imp","Nacetylglycine_imp","sarcosine_imp",
 "dimethylglycine_imp","betaine_imp")
met
                          [,1]
glycine_imp         0.61532855
Nacetylglycine_imp  0.04294675
sarcosine_imp       0.98840385
dimethylglycine_imp 0.00507230
betaine_imp         0.68528107

In your example, I think you are mixing up the names and the values of
"met". I suspect that you want to use the values for the computation
and the names for the filenames. Also, a one column matrix will act
very much like a vector, but there are a few problems if you treat it
like one. For instance, if you extract a value as though met is a
vector:

met[2]
[1] 0.04294675

you just get the value, not the rowname. Using both indices extracts
both the value and the name.

met[2,1]
Nacetylglycine_imp
        0.04294675

As I don't have any idea what the other values in your formula are, I
will take the liberty of giving them some:

metalofGT<-100
egfr_v1_ckdepi<-1.2
pc1<-2.3
pc2<-3.4
pc3<-4.5
V1AGE01<-27
GENDER<-"F"

Before embarking on the loop, I think you have confused the "name of
the function", which is "Score", with the return value of the
function. I don't think you want to change the function's name or it
won't work unless you change the name in the function call. Therefore,
I am going to make a blind guess and assume that you want the name of
the return value of the function to be the rowname for the value that
is used in the function.

Now you can do something like this:

for(i in 1:nrow(met)) {
 x<-Scores(Z=metalofGT,formula="met[i]~egfr_v1_ckdepi+pc1+pc2+pc3+V1AGE01+GENDER")
 names(x)<-names(met)[i]
 filename<-paste("prep",i,".Rdata",sep="")
 save(x, file=filename, compress="bzip2")
}

This will produce five files with the names you requested, each
containing whatever value the function "Score" produces. The name of
that value will be the rowname of "met" that produced it.

Jim
On Fri, Jul 3, 2015 at 2:48 AM, Lida Zeighami <lid.zigh at gmail.com> wrote: