[R] Error in match.names(clabs, names(xi))
David Winsemius
dwinsemius at comcast.net
Wed Apr 6 04:44:52 CEST 2011
On Apr 5, 2011, at 8:28 PM, Quan Zhou wrote:
> Hi Guys,
> I have this part of a program:
> library(survival)
> Gastric <- cbind.data.frame(Gp=c(rep(1,45),rep(0,45)), ### 2nd gp 0
> time=c(1,63,105,129,182,216,250,262,301,301,342,354,356,358,
> 380,383, 383,388,394,408,460,489,499,523,524,535,562,569,675,676,
>
> 748,778,786,797,955,968,1000,1245,1271,1420,1551,1694,2363,2754,2950,
>
> 17,42,44,48,60,72,74,95,103,108,122,144,167,170,183,185,193,195,197,
>
> 208,234,235,254,307,315,401,445,464,484,528,542,547,577,580,795,855,
> 1366,1577,2060,2412,2486,2796,2802,2934,2988), Dth=c(rep(1,43),
> 0,0, rep(1,39), rep(0,6)))
> CoxG0 <- coxph(Surv(time,Dth) ~ Gp, Gastric)
> srvGastA <- survfit(Surv(Gastric$time,Gastric$Dth)~1) ## 88 distinct
> times
> #Gastric$time is all the time points either death or largest
> obervation
> time.
> #srvGastA$time is all the unique times
> newGas <- data.frame(start=0, stop=1, Dth=1, Ploidy=1, tim=0)
> #newGas <- r(0,1,1,1,0)
> for (i in 2:90) {
> timind <- match(Gastric$time[i],srvGastA$time)
> tmpmat <- array(0, dim=c(timind,5))#build an array with
> dim('index',5)
> tmpmat[,4] <- rep(Gastric[i,1], timind)#fourth column, return i's
> group
> tmpmat[timind,3] <- Gastric$Dth[i]
> tmpmat[,1] <- if(timind>1) c(0,srvGastA$time[1:(timind-1)]) else 0
> tmpmat[,2] <- srvGastA$time[1:timind]
> newGas <- rbind(newGas,tmpmat) }
You haven't told us what you expect (or even what you are trying to
do), but if you add an assignment of colnames before the final
rbind()-ing of a data.frame and a matrix you get some sort of result:
.....
+ tmpmat[,2] <- srvGastA$time[1:timind] ; colnames(tmpmat) <-
names(newGas)
+ newGas <- rbind(newGas,tmpmat) }
> str(newGas)
'data.frame': 3988 obs. of 5 variables:
$ start : num 0 0 1 17 42 44 48 60 0 1 ...
$ stop : num 1 1 17 42 44 48 60 63 1 17 ...
$ Dth : num 1 0 0 0 0 0 0 1 0 0 ...
$ Ploidy: num 1 1 1 1 1 1 1 1 1 1 ...
$ tim : num 0 0 0 0 0 0 0 0 0 0 ...
> ____________________________________________________________________
> I found when include "the last line" in the for loop. the error will
> jump
> out. But I do not know how to fix it. I initialize newGas without
> names.
Good luck with trying to make a data.frame without column names.
> it
> does not work either....
> It would be great if anyone knows how to fix the problem. Thanks a
> lot.
> BR
> Quan
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list