-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Ajay Shah
Sent: Sunday, October 03, 2004 4:10 AM
To: r-help
Subject: [R] Making a 'joint distribution'?
Suppose I make two discrete variables --
D <- data.frame(f1=sample(1:5,100,replace=T),
f2=sample(1:5,100,replace=T))
0 1 2 3 4
0 5 5 5 5 4
1 4 2 6 7 3
2 5 3 5 3 6
3 3 1 3 1 2
4 6 4 3 3 6
0 1 2 3 4
23 15 22 19 21
which is all great. But how do I produce the typical
presentation of the "joint distribution" where we put the
marginal distributions in the margins? E.g. I'd like to get
some object "joint" where one would get :
0 1 2 3 4 f1
0 5 5 5 5 4 24
1 4 2 6 7 3 22
2 5 3 5 3 6 22
3 3 1 3 1 2 10
4 6 4 3 3 6 22
f2 23 15 22 19 21 100
So that one could then say "joint/nrow(D)" and get nice
probabilities out of it. It would great to be able to say
"xtable(joint/nrow(D))" :-)
I'm sure R has a lovely way to do this, but I'm not able to
figure it out.
--
Ajay Shah Consultant
ajayshah at mayin.org Department of Economic Affairs
http://www.mayin.org/ajayshah Ministry of Finance, New Delhi