Re: [R] Need Help for creating a new variable

2009-02-19 Thread Stavros Macrakis
On Thu, Feb 19, 2009 at 9:50 AM, Jorge Ivan Velez wrote: > mydata$trt<-with(mydata,paste(diet,vesl,sep="")) Besides the above (good!) solution, you might want to understand why your original solution didn't work: >> > mydata$trt<-ifelse(mydata$diet=="C" && mydata$vesl=="A", "CA", >> +

Re: [R] Need Help for creating a new variable

2009-02-19 Thread Jorge Ivan Velez
Dear Chun-Hao, How about this? diet<-sort(rep(x=c("C","T"),4)) vesl<-rep(x=c("A","P"),4) mydata<-data.frame(diet,vesl) mydata$trt<-with(mydata,paste(diet,vesl,sep="")) mydata HTH, Jorge On Thu, Feb 19, 2009 at 2:53 AM, Chun-Hao Tu wrote: > > > Hi R users, > > I did do the research and work o

Re: [R] Need Help for creating a new variable

2009-02-19 Thread Mark Difford
Hi Chun, >> I did do the research and work on for hours ... I try to creat a new >> variable in my dataset. Yes, looks like you did. Look at ?interaction, which gives you more flexibility than ?":". ## Example diet<-sort(rep(x=c("C","T"),4)) vesl<-rep(x=c("A","P"),4) mydata<-data.frame(diet,v