On Thu, Feb 19, 2009 at 9:50 AM, Jorge Ivan Velez
<jorgeivanve...@gmail.com> 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",
>> +            ifelse(mydata$diet=="C" && mydata$vesl=="P", "CP",
>> +              ifelse(mydata$diet=="T" && mydata$vesl=="A", "TA",
>> +                 ifelse(mydata$diet=="T" && mydata$vesl=="P", "TP"))))

The problem here is that you are using && rather than &.  From the man page:

     '&' and '&&' indicate logical AND and '|' and '||' indicate
     logical OR.  The shorter form performs elementwise comparisons in
     much the same way as arithmetic operators.  The longer form
     evaluates left to right examining only the first element of each
     vector.

I trust this makes things clearer.

         -s

______________________________________________
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.

Reply via email to