Skip to content

Newbie struggling with "factors"

2 messages · Tom Arnold, Frank E Harrell Jr

#
To all who have offered suggestions: 
THANKS! Wow, this list has generated a lot of good
ideas for me in a very short time, and I appreciate
it.

For now, I've got some solutions to my problem. Greg's
suggestion about creating a subclass to handle the
"multi-checkbox" type of question is probably the most
flexible, in the long run. However, I've not chosen it
in the short run because my programming experience is
deeper in the procedural vein than in OOP. I'm only
just starting to see how the OO qualities of R can be
used, and I'm not yet comfortable in coding that way.

Following the suggestions of several people on the
list, I have created a few functions that proceed this
way for my multi-choice questions:
- create a matrix with as many rows as there are
responses, and as many columns as there are
"checkboxes" in the original question

- use strsplit to break up the factors based on the
separator inside the field

- for each column in the matrix that I created, fill
it with T/F (1/0) by using the is.element function to
determine which responses had each checkbox checked

- use the resulting matrix to create whatever sums,
averages and plots I want

The code I wrote is not pretty, but is working for me
at the moment. I'm an old assembly and C programmer
mainly, so I'm still getting used to the capabilities
and idioms of R. I think my code does great violence
to both and probably makes the interpreter thrash
pitifully, but for now it seems to produce the correct
result and I can understand it! I'll look for elegance
as I go along.
--- "Warnes, Gregory R"
<gregory_r_warnes at groton.pfizer.com> wrote:
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
=== message truncated ===


=====
Tom Arnold
Summit Media Partners
Visit our web site at http://www.summitmediapartners.com

__________________________________________________

Yahoo! Greetings - send holiday greetings for Easter, Passover

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
The Hmisc library has a multiple choice class that uses the matrix storage approach.  I only do anything with this class in the summary.formula function for table making.  The library is ready for beta testing for Linux/Unix users and soon for Windows.  I will make a full announcement when the Windows port is ready.

You may obtain the Linux/Unix package from http://hesweb1.med.virginia.edu/biostat/s/Hmisc.html

For examples of using summary.formula for handling multiple choice data see
http://hesweb1.med.virginia.edu/biostat/s/help/Hmisc/html/summary.formula.html

Frank Harrell

On Fri, 29 Mar 2002 14:17:57 -0800 (PST)
Tom Arnold <thomas_l_arnold at yahoo.com> wrote: