Hi All, I've the following data frame with 54 rows and 4 colums:> xRatio Dose Time Batch R.010mM.04h.NEW 0.02 010mM 04h NEW R.010mM.04h.NEW.1 0.07 010mM 04h NEW ... R.010mM.24h.NEW.2 0.06 010mM 24h NEW R.010mM.04h.OLD 0.19 010mM 04h OLD ... R.010mM.04h.OLD.1 0.49 010mM 04h OLD R.100mM.24h.OLD 0.40 100mM 24h OLD I'd like to create a sub data frame containing all rows where Batch == "OLD" and keeping the 4 colums. Assume that I don't know the order of the rows (otherwise I could just do something like x[1:20,]). I've tried x[x$Batch == 'OLD'] or x[x[,4] == 'OLD'] but it generates errors. So I assume I've still not realy understood the philosophy of indexing ... :-( What's the easiest way to do this, any suggestions? thanks a lot for you help, Arne
Sorry, I just figured it out: x[x$Batch == 'OLD',] instead of x[x$Batch ='OLD']. I didn't know this has to be in the same format then x[1:20,] where I already used the comma. sorry for posting the previous message ... Arne> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of > Arne.Muller at aventis.com > Sent: 17 October 2003 12:12 > To: r-help at stat.math.ethz.ch > Subject: [R] sub data frame by expression > > > Hi All, > > I've the following data frame with 54 rows and 4 colums: > > > x > Ratio Dose Time Batch > R.010mM.04h.NEW 0.02 010mM 04h NEW > R.010mM.04h.NEW.1 0.07 010mM 04h NEW > ... > R.010mM.24h.NEW.2 0.06 010mM 24h NEW > R.010mM.04h.OLD 0.19 010mM 04h OLD > ... > R.010mM.04h.OLD.1 0.49 010mM 04h OLD > R.100mM.24h.OLD 0.40 100mM 24h OLD > > I'd like to create a sub data frame containing all rows where > Batch == "OLD" > and keeping the 4 colums. Assume that I don't know the order > of the rows > (otherwise I could just do something like x[1:20,]). > > I've tried x[x$Batch == 'OLD'] or x[x[,4] == 'OLD'] but it > generates errors. > So I assume I've still not realy understood the philosophy of > indexing ... > :-( > > What's the easiest way to do this, any suggestions? > > thanks a lot for you help, > > Arne > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >
On Fri, 17 Oct 2003 Arne.Muller at aventis.com wrote:> I've the following data frame with 54 rows and 4 colums: > > > x > Ratio Dose Time Batch > R.010mM.04h.NEW 0.02 010mM 04h NEW > R.010mM.04h.NEW.1 0.07 010mM 04h NEW > ... > R.010mM.24h.NEW.2 0.06 010mM 24h NEW > R.010mM.04h.OLD 0.19 010mM 04h OLD > ... > R.010mM.04h.OLD.1 0.49 010mM 04h OLD > R.100mM.24h.OLD 0.40 100mM 24h OLD > > I'd like to create a sub data frame containing all rows where Batch == "OLD" > and keeping the 4 colums. Assume that I don't know the order of the rows > (otherwise I could just do something like x[1:20,]). > > I've tried x[x$Batch == 'OLD'] or x[x[,4] == 'OLD'] but it generates errors.That subsets columns, not rows. Try x[x$Batch == "OLD",] -- Brian D. Ripley, ripley at stats.ox.ac.uk 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, UK Fax: +44 1865 272595
Hoi Arne.Muller at aventis.com, --On vrijdag 17 oktober 2003 12:11 +0200 Arne.Muller at aventis.com wrote:> I'd like to create a sub data frame containing all rows where Batch => "OLD" and keeping the 4 colums. Assume that I don't know the order of the > rowssubset(x, Batch == 'Old') or something like that!? -- Paul Lemmens NICI, University of Nijmegen ASCII Ribbon Campaign /"\ Montessorilaan 3 (B.01.03) Against HTML Mail \ / NL-6525 HR Nijmegen X The Netherlands / \ Phonenumber +31-24-3612648 Fax +31-24-3616066
Hi, thanks for your replies regarding the problem to select a sub data frame by expression. I start getting an understanding on how indexing works in R. thanks for your replies, Arne> -----Original Message----- > From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk] > Sent: 17 October 2003 12:38 > To: Muller, Arne PH/FR > Cc: r-help at stat.math.ethz.ch > Subject: Re: [R] sub data frame by expression > > > On Fri, 17 Oct 2003 Arne.Muller at aventis.com wrote: > > > I've the following data frame with 54 rows and 4 colums: > > > > > x > > Ratio Dose Time Batch > > R.010mM.04h.NEW 0.02 010mM 04h NEW > > R.010mM.04h.NEW.1 0.07 010mM 04h NEW > > ... > > R.010mM.24h.NEW.2 0.06 010mM 24h NEW > > R.010mM.04h.OLD 0.19 010mM 04h OLD > > ... > > R.010mM.04h.OLD.1 0.49 010mM 04h OLD > > R.100mM.24h.OLD 0.40 100mM 24h OLD > > > > I'd like to create a sub data frame containing all rows > where Batch == "OLD" > > and keeping the 4 colums. Assume that I don't know the > order of the rows > > (otherwise I could just do something like x[1:20,]). > > > > I've tried x[x$Batch == 'OLD'] or x[x[,4] == 'OLD'] but it > generates errors. > > That subsets columns, not rows. Try x[x$Batch == "OLD",] > > -- > Brian D. Ripley, ripley at stats.ox.ac.uk > 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, UK Fax: +44 1865 272595 > >