Thanks to everyone who helped me solve this question. My cleanest
solution is:
joint.and.marginals - function(x,y) {
t - addmargins(table(x, y))
rownames(t)[nrow(t)] - deparse(substitute(y))
colnames(t)[ncol(t)] - deparse(substitute(x))
return(t)
}
There are many other valid solutions,
Ajay Shah ajayshah at mayin.org writes:
:
: Thanks to everyone who helped me solve this question. My cleanest
: solution is:
:
: joint.and.marginals - function(x,y) {
: t - addmargins(table(x, y))
: rownames(t)[nrow(t)] - deparse(substitute(y))
: colnames(t)[ncol(t)] -
Gabor Grothendieck ggrothendieck at myway.com writes:
:
: Ajay Shah ajayshah at mayin.org writes:
:
: :
: : Thanks to everyone who helped me solve this question. My cleanest
: : solution is:
: :
: : joint.and.marginals - function(x,y) {
: : t - addmargins(table(x, y))
: :
))
colnames(tab)[ncol(tab)] - deparse(substitute(x))
tab
}
I hope this helps,
John
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Ajay Shah
Sent: Sunday, October 03, 2004 4:10 AM
To: r-help
Subject: [R] Making a 'joint
On Sun, 3 Oct 2004, Ajay Shah wrote:
Suppose I make two discrete variables --
D - data.frame(f1=sample(1:5,100,replace=T), f2=sample(1:5,100,replace=T))
sniP
which is all great. But how do I produce the typical presentation of
the joint distribution where we put the marginal distributions in
the
Suppose I make two discrete variables --
D - data.frame(f1=sample(1:5,100,replace=T), f2=sample(1:5,100,replace=T))
I know I can do:
table(D$f1, D$f2)
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
table(D$f1)
0 1 2 3 4
24 22 22 10 22
table(D$f2)