[R] Matrix of Index Variables
Jason Turner
jasont at indigoindustrial.co.nz
Mon Oct 20 23:08:46 CEST 2003
TyagiAnupam at aol.com wrote:
> What is a good way to create a matrix of index variables based on all
> possible combinations of a list of factors in a data-frame, say list(age, sex)? "age"
> and "sex" are numeric and factor variables in a dataframe, with 99 and 2
> values, respectively.
> I would like to use these for subsetting the data-frame, apply functions to
> subset and collecting the results.
>
Rather than creating a new index, I think you want the function "by()".
Something like
foo <- by(mydata,list(age=mydata$age, sex=mydata$sex),
your.summary.function)
Cheers
Jason
--
Indigo Industrial Controls Ltd.
http://www.indigoindustrial.co.nz
64-21-343-545
jasont at indigoindustrial.co.nz
More information about the R-help
mailing list