Hello, I have this command: x.axis <- seq(from=0.5, to=4.5, length.out=13112) How can I which of the x.axis components is the closest to a given value, for example 3.2? Best, Dani -- Daniel Valverde Saub? Grup de Biologia Molecular de Llevats Facultat de Veterin?ria de la Universitat Aut?noma de Barcelona Edifici V, Campus UAB 08193 Cerdanyola del Vall?s- SPAIN Centro de Investigaci?n Biom?dica en Red en Bioingenier?a, Biomateriales y Nanomedicina (CIBER-BBN) Grup d'Aplicacions Biom?diques de la RMN Facultat de Bioci?ncies Universitat Aut?noma de Barcelona Edifici Cs, Campus UAB 08193 Cerdanyola del Vall?s- SPAIN +34 93 5814126
Try this: x.axis[which.min(abs(x.axis - 3.2))] On Wed, Aug 27, 2008 at 10:12 AM, Dani Valverde <daniel.valverde at uab.cat> wrote:> Hello, > I have this command: > x.axis <- seq(from=0.5, to=4.5, length.out=13112) > How can I which of the x.axis components is the closest to a given value, > for example 3.2? > Best, > > Dani > > -- > Daniel Valverde Saub? > > Grup de Biologia Molecular de Llevats > Facultat de Veterin?ria de la Universitat Aut?noma de Barcelona > Edifici V, Campus UAB > 08193 Cerdanyola del Vall?s- SPAIN > > Centro de Investigaci?n Biom?dica en Red > en Bioingenier?a, Biomateriales y > Nanomedicina (CIBER-BBN) > > Grup d'Aplicacions Biom?diques de la RMN > Facultat de Bioci?ncies > Universitat Aut?noma de Barcelona > Edifici Cs, Campus UAB > 08193 Cerdanyola del Vall?s- SPAIN > +34 93 5814126 > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Hi r-help-bounces at r-project.org napsal dne 27.08.2008 15:12:58:> Hello, > I have this command: > x.axis <- seq(from=0.5, to=4.5, length.out=13112) > How can I which of the x.axis components is the closest to a given > value, for example 3.2E.g. which.min((x.axis-3.2)^2) Regards Petr> Best, > > Dani > > -- > Daniel Valverde Saub? > > Grup de Biologia Molecular de Llevats > Facultat de Veterin?ria de la Universitat Aut?noma de Barcelona > Edifici V, Campus UAB > 08193 Cerdanyola del Vall?s- SPAIN > > Centro de Investigaci?n Biom?dica en Red > en Bioingenier?a, Biomateriales y > Nanomedicina (CIBER-BBN) > > Grup d'Aplicacions Biom?diques de la RMN > Facultat de Bioci?ncies > Universitat Aut?noma de Barcelona > Edifici Cs, Campus UAB > 08193 Cerdanyola del Vall?s- SPAIN > +34 93 5814126 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Maybe this which.min(abs(x.axis-3.2))> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Dani Valverde > Sent: Wednesday, August 27, 2008 9:13 AM > To: R Help > Subject: [R] Closest value > > Hello, > I have this command: > x.axis <- seq(from=0.5, to=4.5, length.out=13112) How can I > which of the x.axis components is the closest to a given > value, for example 3.2? > Best, > > Dani > > -- > Daniel Valverde Saub? > > Grup de Biologia Molecular de Llevats > Facultat de Veterin?ria de la Universitat Aut?noma de > Barcelona Edifici V, Campus UAB > 08193 Cerdanyola del Vall?s- SPAIN > > Centro de Investigaci?n Biom?dica en Red en Bioingenier?a, > Biomateriales y Nanomedicina (CIBER-BBN) > > Grup d'Aplicacions Biom?diques de la RMN Facultat de > Bioci?ncies Universitat Aut?noma de Barcelona Edifici Cs, Campus UAB > 08193 Cerdanyola del Vall?s- SPAIN > +34 93 5814126 > > ______________________________________________ > 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. >