[R] Closest value

Henrique Dallazuanna wwwhsd at gmail.com
Wed Aug 27 15:22:03 CEST 2008


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



More information about the R-help mailing list