Re: [R] simplify code for dummy coding of factors

2014-12-30 Thread Richard M. Heiberger
It can handle one more simplification step # Rich Heiberger, removing intercept, including haireye data haireye.df <- cbind( as.data.frame(haireye), model.matrix(Freq ~ Hair + Eye, data=haireye, contrasts.arg=list(Hair=diag(4), Eye=diag(4)))[,-1] ) haireye.df On Tue, Dec 30, 2

Re: [R] simplify code for dummy coding of factors

2014-12-30 Thread Michael Friendly
On 12/30/14 7:16 PM, Richard M. Heiberger wrote: I like this very simple version. Note that you don't need as.data.frame(). model.matrix(Freq ~ Hair + Eye, data=haireye, contrasts.arg=list(Hair=diag(4), Eye=diag(4))) Thanks to all who replied to this question. model.matrix() was what I had mi

Re: [R] simplify code for dummy coding of factors

2014-12-30 Thread Jeff Newmiller
"More comprehensible" depends on context, which we don't have. You could be simply trying to illustrate the logic of the transformation (solution 1 below) or providing a recipe which by its brevity is (perhaps?) memorable (solution 2 below). Solution 1: appendDummys <- function( DF, keycol, d

Re: [R] simplify code for dummy coding of factors

2014-12-30 Thread Richard M. Heiberger
I like this very simple version. Note that you don't need as.data.frame(). model.matrix(Freq ~ Hair + Eye, data=haireye, contrasts.arg=list(Hair=diag(4), Eye=diag(4))) On Tue, Dec 30, 2014 at 6:05 PM, Michael Friendly wrote: > In a manuscript, I have the following code to illustrate dummy codin

Re: [R] simplify code for dummy coding of factors

2014-12-30 Thread David Winsemius
On Dec 30, 2014, at 3:05 PM, Michael Friendly wrote: > In a manuscript, I have the following code to illustrate dummy coding of two > factors in a contingency table. > > It works, but is surely obscured by the method I used, involving outer() to > find equalities and 0+outer() > to convert to

Re: [R] simplify code for dummy coding of factors

2014-12-30 Thread John Fox
oject.org] On Behalf Of Michael > Friendly > Sent: Tuesday, December 30, 2014 6:05 PM > To: R-help > Subject: [R] simplify code for dummy coding of factors > > In a manuscript, I have the following code to illustrate dummy coding of > two factors in a contingency table. > &g

[R] simplify code for dummy coding of factors

2014-12-30 Thread Michael Friendly
In a manuscript, I have the following code to illustrate dummy coding of two factors in a contingency table. It works, but is surely obscured by the method I used, involving outer() to find equalities and 0+outer() to convert to numeric. Can someone help simplify this code to be more comprehe