Hi,

I was hoping someone could help figure out how to write code for R to do the below.

I have data that looks like below. Variables, sid and pid are strings, slope is numeric. I need R to get me the mean of slopes for all pid's nested within each sid if there are more than one pid's nested within sid.

If there is only pid for a sid, like for 2.1 below, I want R to write a 0.

In the data below, I want to get the mean of slopes for pid (1.1; 4.1; and 5.1) because they are nested within sid 1.1 and so on.

Thanks in advance for any suggestions.
Swaroop

sid        pid        slope
1.1        1.1        2
1.1        4.1        3
1.1        5.1        2
2.1        5.1        3
3.2        1.2        2
3.2        1.7        3




	[[alternative HTML version deleted]]


