Re: [R] Help with for/if loop

2009-04-23 Thread David Winsemius
On Apr 23, 2009, at 8:07 PM, Giggles_Fairy wrote: I have a set of data that includes various data columns. One if the survival time and another if a continuous variable of ages. I want to put the ages into intervals so that I can then perform the Kalpan Meier test. I am trying to use the

Re: [R] Help with for/if loop

2009-04-23 Thread andrew
or perhaps agec <- 0*age age[age<=46] <- 1 age[age>46 & age<=58 <- 2 age[age>58] <- 3 or perhaps a one liner cut(x = age, breaks= c(0,46, 58,Inf), labels = c(1,2,3)) On Apr 24, 11:24 am, Jorge Ivan Velez wrote: > Dear Hollie, > ifelse() is one alternative in this particular case: > > # Some

Re: [R] Help with for/if loop

2009-04-23 Thread Jorge Ivan Velez
Dear Hollie, ifelse() is one alternative in this particular case: # Some data age<- c(46,47,43,46,47,59,50,54,59,60) ifelse(age<=46, 1, ifelse( age>46 & age<=58 , 2, 3) ) [1] 1 2 1 1 2 3 2 2 3 3 See ?ifelse for more details. HTH, Jorge On Thu, Apr 23, 2009 at 8:07 PM, Giggles_Fairy

[R] Help with for/if loop

2009-04-23 Thread Giggles_Fairy
I have a set of data that includes various data columns. One if the survival time and another if a continuous variable of ages. I want to put the ages into intervals so that I can then perform the Kalpan Meier test. I am trying to use the following code to build a column with the age group numbers