Re: [R] Creating data using multiple for loops

2019-08-18 Thread Jim Lemon
Hi Greg, One problem is that you have misplaced the closing brace in the third loop. It should follow the assignment statement. Because you used loops rather than Bert's suggestion, perhaps you are trying to order the values assigned. In your example, the ordering will be ssn, then month of birth,

Re: [R] Partition a vector into select groups with fixed length

2019-08-18 Thread Rui Barradas
Hello, Bert's modular arithmetic way simplifies my code a lot. breakVec <- function(x, n = 5){ if(n < 1) stop(paste("Illegal value n:", n)) f <- if(n == 1) "" else (seq_along(x) - 1) %/% n split(x, f) } Hope this helps, Rui Barradas Às 20:08 de 18/08/19, Bert Gunter escreveu: Perhaps

Re: [R] Creating data using multiple for loops

2019-08-18 Thread Bert Gunter
id <- do.call(paste0,expand.grid(0:9, 1:3, 1:5)) Comment: If you use R much, you'll do much better using R language constructs than trying to apply those from other languages (Java perhaps?). I realize this can be difficult, especially if you are experienced in the another language (or languages),

Re: [R] Partition a vector into select groups with fixed length

2019-08-18 Thread Bert Gunter
Perhaps simpler: Hint: (seq_along(LETTERS) -1) %/% 5 ## modular arithmetic can be useful for this sort of thing Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) O

[R] Creating data using multiple for loops

2019-08-18 Thread g . eastham . gilbert
I would like to create pseudo identification numbers in the format of last four of a social security number ( to ), month of birth (01 to 12), and day of birth (01-28). The IDs can be character. I have gotten this far: for (ssn in 0:9){ for (month in 1:3){ for (day in 1:5){

Re: [R] Partition a vector into select groups with fixed length

2019-08-18 Thread Gerrit Eichner
Hi, Christofer, try something along len <- 5 split(Vec, rep(seq(ceiling(length(Vec)/len)), each = len)) Hth -- Gerrit - Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eich...@math.uni-giessen.d

Re: [R] Partition a vector into select groups with fixed length

2019-08-18 Thread Rui Barradas
Hello, The following function will do it. It uses a standard cumsum trick to create a break vector f. And predicts special cases (n = 0 or n = 1). breakVec <- function(x, n = 5){ if(n < 1) stop(paste("Illegal value n:", n)) if(n == 1){ f = "" }else{ f <- c(1, rep(0, n - 1)) f <

[R] Partition a vector into select groups with fixed length

2019-08-18 Thread Christofer Bogaso
Hi, Let say I have a vector as below Vec = LETTERS Now I want to break this vector into groups of the same length of 5. So, 1st group consists - "A" "B" "C" "D" "E" 2nd group - "F" "G" "H" "I" "J" and so on.. last group will consist only the leftover elements I have a very large initial vecto

[R] results of a survival analysis change when converting the data to counting process format

2019-08-18 Thread Ferenci Tamas
Dear All, Consider the following simple example: library( survival ) data( veteran ) coef( coxph(Surv(time, status) ~ trt + prior + karno, data = veteran) ) trtpriorkarno 0.180197194 -0.005550919 -0.033771018 Note that we have neither time-dependent covariates, nor ti

Re: [R] conflicting results for a time-varying coefficient in a Cox model

2019-08-18 Thread Ferenci Tamas
Dear Dr. Therneau, Thank you very much for your exhaustive answer! I now see the issue. Perhaps even more important was your confirmation that my approach with karno:ns(time, df=4) is theoretically correct. (I knew that plot.cox.zph is sound, so I was afraid that the difference can be attribute