Hi Tristan,
Matrices are single mode structures (ie. they can only hold a single type of data at any time).
When you "rbind" a matrix including "y[1]" you effectively are including
character data (as y is character) into a matrix. Hence all the matrix is coerced to characters.
You may also want to look at restructuring your code using applys and do.call.
Something like this (untested) code perhaps:
z2 <- paste("csgg", y, sep="")
outList <- lapply(z2, function(txt) {
w2 <- get(txt)
w1 <- survReg(Surv(w2[,2],w2[,3], type="interval2")~w2$Granulo,
dist="weibull",na.action=na.exclude)
c(w1$scale,w1$coef[1:2])
})
do.call("rbind", outList)
Hope this helps,
Romain.
mangosolutions
S & R training and consulting services
Tristan Lorino wrote:
Hi,
In this example, I fit several Weibull survival models and I put the
numerical results (scale, intercept and coefficient) in a length(y)x4
matrix. But the output matrix A is character, so I can't make
calculations on the results!
I don't understand why A is non-numerical matrix. How can I get
numerical values?
y_c("005","01","015","02","025","03","035","04","045","05","055","06","065","07","075","08","085")
z2_outer("csgg",y,paste,sep="")
A_matrix(NULL,ncol=4)
for (i in 1:length(y))
{
w2_get(z2[i])
w1_survReg(Surv(w2[,2],w2[,3], type="interval2")~w2$Granulo,
dist="weibull",na.action=na.exclude)
A_rbind(A,c(y[i],w1$scale,w1$coef[1],w1$coef[2]))
A
}
A
dimnames(A)[[2]]_c("threshold","scale","intercept","coef")
mean(A[,2])
[1] NA
Warning messages:
mean of data of class "character" undefined, returning NA in: mean(A[, 2])
Thank you,
Tristan Lorino
--
Mango Solutions
data analysis that delivers
Tel: +44(0) 1249 467 467
Fax: +44(0) 1249 467 468
Mob: +44(0) 7813 526 123
|