Hi all, I have a rather naive question. I have the height of 100 individuals in a table and I want to assign the tallest 30% as Case=1 and the bottom 30% as Case=0. How do I do that? thanks. jiong The email message (and any attachments) is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message (and any attachments). Thank You. [[alternative HTML version deleted]]
My solutions are usually too baroque, but does this do what you want? x <- rnorm(100) quants <- quantile(x, c(.3, .7)) Case <- rep(2, length(x)) # 2 lies in the middle of the distribution Case[x <= quants[1]] <- 0 Case[x >= quants[2]] <- 1 Case Cheers, Simon. On Mon, 2007-06-11 at 15:14 -0700, Jiong Zhang, PhD wrote:> Hi all, > > I have a rather naive question. I have the height of 100 individuals in > a table and I want to assign the tallest 30% as Case=1 and the bottom > 30% as Case=0. How do I do that? > > thanks. > > jiong > The email message (and any attachments) is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message (and any attachments). Thank You. > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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.-- Simon Blomberg, BSc (Hons), PhD, MAppStat. Lecturer and Consultant Statistician Faculty of Biological and Chemical Sciences The University of Queensland St. Lucia Queensland 4072 Australia Room 320, Goddard Building (8) T: +61 7 3365 2506 email: S.Blomberg1_at_uq.edu.au The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. - John Tukey.
Simon Blomberg <s.blomberg1 <at> uq.edu.au> writes:> > My solutions are usually too baroque, but does this do what you want? > > x <- rnorm(100) > quants <- quantile(x, c(.3, .7)) > Case <- rep(2, length(x)) # 2 lies in the middle of the distribution > Case[x <= quants[1]] <- 0 > Case[x >= quants[2]] <- 1 > Case > > On Mon, 2007-06-11 at 15:14 -0700, Jiong Zhang, PhD wrote: > > Hi all, > > > > I have a rather naive question. I have the height of 100 individuals in > > a table and I want to assign the tallest 30% as Case=1 and the bottom > > 30% as Case=0. How do I do that? > >Or, how about, x <- rnorm(100) Case <- cut(x, quantile(x, c(0, 0.3, 0.7, 1)), c(0, 2, 1), TRUE) ken -- Ken Knoblauch Inserm U846 Institut Cellule Souche et Cerveau D?partement Neurosciences Int?gratives 18 avenue du Doyen L?pine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.pizzerialesgemeaux.com/u846/
See ?quantcut in the gtools package. On 6/11/07, Jiong Zhang, PhD <jizhang at chori.org> wrote:> Hi all, > > I have a rather naive question. I have the height of 100 individuals in > a table and I want to assign the tallest 30% as Case=1 and the bottom > 30% as Case=0. How do I do that? > > thanks. > > jiong > The email message (and any attachments) is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message (and any attachments). Thank You. > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >