On Mon, Oct 20, 2008 at 11:14 AM, jim holtman <[EMAIL PROTECTED]> wrote: > yet another way (as it always is in R): > >> x<-c(1,0,0,1,0,0,1,0,0,1) >> y<-c(1,3,2,3,2,1,2,3,2,3) >> z<-c(1,2,1,2,1,2,1,2,1,2) >> d<-as.data.frame(cbind(x,y,z)) >> d$myvar <- x*6 + (y-1)*2 + z >> >> d > x y z myvar > 1 1 1 1 7 > 2 0 3 2 6 > 3 0 2 1 3 > 4 1 3 2 12 > 5 0 2 1 3 > 6 0 1 2 2 > 7 1 2 1 9 > 8 0 3 2 6 > 9 0 2 1 3 > 10 1 3 2 12
That's equivalent to as.numeric(interaction(x, y, z)) but in my experience is much much faster (which of course only matters for huge datasets). Hadley -- http://had.co.nz/ ______________________________________________ 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.