if I've understood your question correctly, you probably need
something like:
x <- data.frame(X1 = rep(c("name1", "name2"), each = 5),
X2 = rep(LETTERS[1:2], 5),
X3 = rep(1:3, length.out = 10),
X4 = rep(c("cat a", "cat", "bb", "re"), length.out =
10))
##################
x. <- x[x$X2 == "A" & x$X4 == "cat a", "X1"]
table(x.)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Colin Maurice" <colinsplus@hotmail.com>
To: <s-news@lists.biostat.wustl.edu>
Sent: Friday, February 17, 2006 4:13 PM
Subject: [S] simple table question
Hello members,
I have a simple tabluation question that has been bugging me for a
bit. I would appreciate any assistance with it.
Suppose I have the following data.frame
x
X1 X2 X3 X4
1 name1 Letter A 1 cat a
2 name1 Letter B 2 cat
3 name1 Letter A 3 bb
4 name1 Letter B 1 re
5 name1 Letter A 2 cat a
6 name2 Letter B 3 cat
7 name2 Letter A 1 bb
8 name2 Letter B 2 re
9 name2 Letter A 3 cat a
10 name2 Letter B 1 cat
I would like a tabulation for each category in X1 when X2 contains
the letter "A", and X4 has occurrence "cat a"
my.names <- unique(x$X1)
my.names2 <- factor(x$X1, my.names)
table(my.names2, regMatch(x$X4, "cat a") & regMatch(x$X2, "A"))
FALSE TRUE
name1 3 2
name2 4 1
I'm only after the true occurences not the false column. How do I
put this conidtion into the table command without using the "[,2]"
at the end of the command.
Thank you for any help.
Colin
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's
FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu
with
the BODY of the message: unsubscribe s-news
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
|