[R] Am I misunderstanding the ifelse construction?
Erich Neuwirth
erich.neuwirth at univie.ac.at
Tue Sep 25 12:10:57 CEST 2007
The thing to remember is that ifelse is a function,
it returns a value, so usually one does not need assignments within the
function call.
You also could do:
negindices <- dir=="-"
gc_content[negindices] <- -gc_content[negindices]
Eik Vettorazzi wrote:
> d <- ifelse(dir == "-", -gc_content , gc_content)
> works. You need not assign gc_content a new value in each comparison,
> because then your "result" depends only on the last value of "dir",
> which happened to be "-", so you got -0.5 for all gc_content.
>
> hth
>
--
Erich Neuwirth, University of Vienna
Faculty of Computer Science
Computer Supported Didactics Working Group
Visit our SunSITE at http://sunsite.univie.ac.at
Phone: +43-1-4277-39464 Fax: +43-1-4277-39459
More information about the R-help
mailing list