[R] selecting by variable
Hi, I'm a recent R convert so I haven't quite figured out the details yet... How do I select one variable by another one? Ie if I want to draw the histogram of variable X only for those individuals that also have a value Y in a certain range? In STATA I would give something like: histogram X if ((Y=A Y=B)) (The data is for individuals and each individual has a number of characteristics including X and Y). thanks, eugene. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] selecting by variable
Eugene, R allows indexing with logical vectors, so your example would look like hist(X[(Y=A) (Y=B)]) See the manual An Introduction to R for details. HTH Thomas -Original Message- From: Eugene Salinas [mailto:[EMAIL PROTECTED] Sent: 27 August 2003 09:49 To: [EMAIL PROTECTED] Subject: [R] selecting by variable Hi, I'm a recent R convert so I haven't quite figured out the details yet... How do I select one variable by another one? Ie if I want to draw the histogram of variable X only for those individuals that also have a value Y in a certain range? In STATA I would give something like: histogram X if ((Y=A Y=B)) (The data is for individuals and each individual has a number of characteristics including X and Y). thanks, eugene. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help --- Thomas Hotz Research Associate in Medical Statistics University of Leicester United Kingdom Department of Epidemiology and Public Health 22-28 Princess Road West Leicester LE1 6TP Tel +44 116 252-5410 Fax +44 116 252-5423 Division of Medicine for the Elderly Department of Medicine The Glenfield Hospital Leicester LE3 9QP Tel +44 116 256-3643 Fax +44 116 232-2976 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] selecting by variable
Eugene Salinas [EMAIL PROTECTED] wrote: How do I select one variable by another one? Ie if I want to draw the histogram of variable X only for those individuals that also have a value Y in a certain range? In STATA I would give something like: histogram X if ((Y=A Y=B)) hist(x[Y=A Y=B]) See: ?Subscript ? -- Philippe Glaziou __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] selecting by variable
On Wed, 27 Aug 2003, Eugene Salinas wrote: I'm a recent R convert so I haven't quite figured out the details yet... Usually it is good to read the manuals when you use a unfamiliar software... How do I select one variable by another one? Ie if I want to draw the histogram of variable X only for those individuals that also have a value Y in a certain range? e.g. x = rnorm(100) y = 1:100 x[y = 20:50] will give you the value of x when y is between 20 and 50. To do a histogram, type: ?hist -- Cheers, Kevin -- On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question. -- Charles Babbage (1791-1871) From Computer Stupidities: http://rinkworks.com/stupid/ -- Ko-Kang Kevin Wang Master of Science (MSc) Student SLC Tutor and Lab Demonstrator Department of Statistics University of Auckland New Zealand Homepage: http://www.stat.auckland.ac.nz/~kwan022 Ph: 373-7599 x88475 (City) x88480 (Tamaki) __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] selecting by variable
hist(X[Y=A Y=B]) `An Introduction to R' explains such things, as do (in more detail) the introductory texts (see the R FAQ). On Wed, 27 Aug 2003, Eugene Salinas wrote: I'm a recent R convert so I haven't quite figured out the details yet... How do I select one variable by another one? Ie if I want to draw the histogram of variable X only for those individuals that also have a value Y in a certain range? In STATA I would give something like: histogram X if ((Y=A Y=B)) (The data is for individuals and each individual has a number of characteristics including X and Y). -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] selecting by variable
On Wed, 27 Aug 2003, Petr Pikal wrote: Hallo On 27 Aug 2003 at 1:49, Eugene Salinas wrote: Hi, I'm a recent R convert so I haven't quite figured out the details yet... How do I select one variable by another one? Ie if I want to draw the histogram of variable X only for those individuals that also have a value Y in a certain range? In STATA I would give something like: histogram X if ((Y=A Y=B)) hist(X[(Y=A)(Y=B)]) if A and B are objects storing your limits ?Logic ?[ (The data is for individuals and each individual has a number of characteristics including X and Y). thanks, eugene. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help Cheers Petr Pikal [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ Salvador Alcaraz Carrasco http://www.umh.es Arquitectura y Tecnología de Computadores http://obelix.umh.es Dpto. Física y Arquitectura de Computadores[EMAIL PROTECTED] Universidad Miguel Hernández [EMAIL PROTECTED] Avda. del ferrocarril, s/n Telf. +34 96 665 8495 Elche, Alicante (Spain) __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help