# Re: [R] Basic stratification calculations

From: Clint Harshaw <charshaw_at_presby.edu>
Date: Fri 04 Mar 2005 - 22:55:29 EST

```> Hi,
> if I understand correctly, tapply() is your friend here,
>
> vito
>
> dvrecko@sfu.ca wrote:
>
```

>>
>> Hi. I'm a student at SFU in Canada. The basic thing I want to do is
>> calculate means of different strata. I have 2 vectors. One has the
>> values I
>> want to take the means from, the other is the four strata I am interested
>> in. So I essentially want to break up the information vector into the
>> four
>> strata and calculate four means, one for each stratum. How can I do
>> this in
>> a reasonable way?
>>
>>
>> Thanks very much.
>> Dean Vrecko
>>
>> PS: Incidentally I forget how to see the code of functions. Does anyone
>> remember the command to do this?
>>
>> ______________________________________________
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> http://www.R-project.org/posting-guide.html
>>
>

Would split(y,f) be of some help here? And then you could find the mean for each level of f:

y.split <- split(y,f)

```mean(y.split\$"0")
mean(y.split\$"1")
mean(y.split\$"2")
mean(y.split\$"3")

```

Clint

```--
Clint Harshaw, PhD		EMail: charshaw@presby.edu
Department of Mathematics	Phone: 864.833.8995
Presbyterian College		Fax: 864.938.3769
Clinton SC  29325		Office: Harrington-Peachtree Rm 412

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help