Thanks for the suggestion, Bert; I just re-read the introduction with
particular attention to the sections you mentioned, but I don't see how any
of it bears on my question.  Namely -- to rephrase:  What constraints are
there on the form of the "yes" and "no" values required by ifelse?   The
introduction doesn't really speak to this, and the help documentation seems
to suggest that as long the shapes of the test, "yes" values, and "no"
values agree, that would be sufficient -- I don't see anything that
specifies that any of these should be of a particular data type.   My
example, however, seems to indicate that the "yes" and "no" values can't be
a mixture of characters and numbers, and I'm trying to figure out what the
underlying constraints are on ifelse.

Thanks again,
David

On Thu, Nov 15, 2012 at 6:46 AM, Bert Gunter <gunter.berton@gene.com> wrote:

> David:
>
> You seem to be getting lost in basic R tasks. Have you read the Intro
> to R tutorial? If not, do so, as this should tell you how to do what
> you need. If so, re-read the sections on indexing ("["), replacement,
> and NA's. Also read about character vectors and factors.
>
> -- Bert
>
> On Thu, Nov 15, 2012 at 3:19 AM, David Romano <dromano@stanford.edu>
> wrote:
> > Hi everyone,
> >
> > I have a data frame one of whose columns is a character vector and the
> rest
> > are numeric, and in debugging a script, I noticed that an ifelse call
> seems
> > to be coercing the character column to a numeric column, and producing
> > unintended values as a result.   Roughly, here's what I tried to do:
> >
> > df: a data frame with, say, the first column as a character column and
> the
> > second and third columns numeric.
> >
> > also: NA's occur only in the numeric columns, and if they occur in one,
> > they occur in the other as well.
> >
> > I wanted to replace the NA's in column 2 with 0's and the ones in column
> 3
> > with 1's, so first I did this:
> >
> >> na.replacements <-ifelse(col(df)==2,0,1).
> >
> > Then I used a second ifelse call to try to remove the NA's as I wanted,
> > first by doing this:
> >
> >> clean.df <- ifelse(is.na(df), na.replacements, df),
> >
> > which produced a list of lists vaguely resembling df, with the NA's
> mostly
> > intact, and so then I tried this:
> >
> >> clean.df <- ifelse(is.na(df), na.replacements, unlist(df)),
> >
> > which seems to work if all the columns are numeric, but otherwise changes
> > strings to numbers.
> >
> > I can't make sense of the help documentation enough to clear this up, but
> > my guess is that the "yes" and "no" values passed to ifelse need to be
> > vectors, in which case it seems I'll have to use another approach
> entirely,
> > but even if is not the case and lists are acceptable, I'm not sure how to
> > convert a mixed-mode data frame into a vector-like list of elements
> (which
> > I would hope would work).
> >
> > I'd be grateful for any suggestions!
> >
> > Thanks,
> > David Romano
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
>
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>

	[[alternative HTML version deleted]]


