I have asked a similar question before but this time
the problem is somewhat more involved. I have the
following data:
case;name;x
1;Joe;1
1;Mike;1
1;Zoe;1
2;Joe;1
2;Mike;0
2;Zoe;1
2;John;1
3;Mike;1
3;Zoe;0
3;Karl;0
I would like to count the number of case
in which any two name
a. both have
dat - read.delim(clipboard, sep=;)
dat - dat[order(dat$case, dat$name), ]
res - apply(combinations(nlevels(dat$name), 2), 1, function(x)
with(dat[dat$name %in%
levels(dat$name)[x],], table(unlist(sapply(split(x, case), function(y)
ifelse(length(y) == 2,
paste(y, collapse=), NA))
Thanks Jacques, this works!
Serguei
--
___
Austrian Institute of Economic Research (WIFO)
Name: Serguei Kaniovski P.O.Box 91
Tel.: +43-1-7982601-231 Arsenal Objekt 20
Fax: +43-1-7989386
I have asked a similar question before but this time
the problem is somewhat more involved. I have the
following data:
case;name;x
1;Joe;1
1;Mike;1
1;Zoe;1
2;Joe;1
2;Mike;0
2;Zoe;1
2;John;1
3;Mike;1
3;Zoe;0
3;Karl;0
I would like to count the number of case
in which any two name
what's different from:
with(dat, tapply(x, list(name,case), sum))
1 2 3
Joe 1 1 NA
John NA 1 NA
Karl NA NA 0
Mike 1 0 1
and how to deal with this table ?
---
Jacques VESLOT
CNRS UMR 8090
I.B.L (2ème étage)
1 rue
what's different from:
with(dat, tapply(x, list(name,case), sum))
1 2 3
Joe 1 1 NA
John NA 1 NA
Karl NA NA 0
Mike 1 0 1
and how to deal with this table ?
Well, the syntax is easier (once you have the data in the correct,
molten, form), and more flexible for other