Re: [R] Applying function to parts of a matrix based on a factor

2010-01-13 Thread Heinz Tuechler
ginal Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of John Sorkin Sent: Wednesday, January 13, 2010 12:11 PM To: r-help@r-project.org Subject: [R] Applying function to parts of a matrix based on a factor R 2.9 Windows XP I have a matrix, Data, whi

Re: [R] Applying function to parts of a matrix based on a factor

2010-01-13 Thread Dimitris Rizopoulos
try this: with(Data, tapply(Age, Sex, mean)) I hope it helps. Best, Dimitris John Sorkin wrote: R 2.9 Windows XP I have a matrix, Data, which contains a factor Sex and a continuous variable Age. I want to get mean age by sex. I know I can do this with two statements, mean(Data["Age,Data[,

Re: [R] Applying function to parts of a matrix based on a factor

2010-01-13 Thread Doran, Harold
with(yourdataframe, tapply(age,sex,mean)) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of John Sorkin Sent: Wednesday, January 13, 2010 12:11 PM To: r-help@r-project.org Subject: [R] Applying function to parts of a matrix based on

[R] Applying function to parts of a matrix based on a factor

2010-01-13 Thread John Sorkin
R 2.9 Windows XP I have a matrix, Data, which contains a factor Sex and a continuous variable Age. I want to get mean age by sex. I know I can do this with two statements, mean(Data["Age,Data[,"Sex"]=="Male") and mean(Data["Age,Data[,"Sex"]=="Female") I know this can be done in a single comman