[R] Error in match.names(clabs, names(xi))
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(timind1) c(0,srvGastA$time[1:(timind-1)]) else 0 tmpmat[,2] - srvGastA$time[1:timind] newGas - rbind(newGas,tmpmat) } 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. it does not work either It would be great if anyone knows how to fix the problem. Thanks a lot. BR Quan [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] index of sort
Hi How can I return the index of sort, when I use R function sort? or any other sorting functions in R For example, I sorted a vector, but R just return the sorted value without giving me the original index of these data. Thanks a lot. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to store a number into a vector
Hi Everyone, A quick question how to store a number like 12345 to a vector or array with size(1,5), like 1, 2, 3, 4, 5 So I can compare if the last three digits of this number is the same with some other numbers. Thanks a lot [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to do linear regression when dimension is high
Thanks! it worked. this forum is so powerful! On Tue, Nov 16, 2010 at 12:20 PM, Douglas Bates ba...@stat.wisc.edu wrote: On Tue, Nov 16, 2010 at 10:30 AM, poko2000 quan.poko2...@gmail.com wrote: Hi I am a newbie in R. I have data with dim of 20. How to use lm if i want to do regression with the whole design matrix? My y is the first column. the left are xs. Thanks a lot. Do you have the data stored in a matrix or in a data frame? If it is in a data frame and the first column is named y then you can use a call like lm(y ~ ., mydata) The '.' on the right hand side of the formula is expanded to a formula incorporating of the columns in the data frame except for the response. For example summary(lm(Fertility ~ ., swiss)) Call: lm(formula = Fertility ~ ., data = swiss) Residuals: Min 1Q Median 3Q Max -15.2743 -5.2617 0.5032 4.1198 15.3213 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 66.91518 10.70604 6.250 1.91e-07 Agriculture -0.172110.07030 -2.448 0.01873 Examination -0.258010.25388 -1.016 0.31546 Education-0.870940.18303 -4.758 2.43e-05 Catholic 0.104120.03526 2.953 0.00519 Infant.Mortality 1.077050.38172 2.822 0.00734 Residual standard error: 7.165 on 41 degrees of freedom Multiple R-squared: 0.7067, Adjusted R-squared: 0.671 F-statistic: 19.76 on 5 and 41 DF, p-value: 5.594e-10 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.