[R] If Then Trouble

From: Sparks, John James <jspark4_at_uic.edu>
Date: Sun, 24 Apr 2011 15:10:36 -0500


Dear R Helpers,

I have another one of those problems involving a very simple step, but due to my inexperience I can't find a way to solve it. I had a look at a number of on-line references, but they don't speak to this problem.

I have a variable with 20 values

> table (testY2$redgroups)

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

   69 734 6079 18578 13693 6412 3548 1646 659 323 129 88 90 40 57 33 36 17 6 13

Values 18,19 and 20 have small counts. So, I want to set the value of redgroups for these rows to 17 in order to combine groups. I would think that it would be as easy as

if(testY2$redgroups>17) testY2$redgroups<-17

following the syntax that I have seen in the manuals. However, I get the error message

Warning message:
In if (testY2$redgroups > 17) testY2$redgroups <- 17 :   the condition has length > 1 and only the first element will be used

Can someone please tell me the correct syntax for this? I would really appreciate it.

Appreciatively yours,
--John J. Sparks, Ph.D.



R-help_at_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. Received on Sun 24 Apr 2011 - 20:15:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 24 Apr 2011 - 21:30:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive