Re: [R] insert() function

From: Henrik Bengtsson <hb_at_stat.berkeley.edu>
Date: Wed, 20 Feb 2008 03:27:32 -0800

Hi.

On Feb 20, 2008 2:38 AM, Dani Valverde <daniel.valverde_at_uab.cat> wrote:
> Hello,
> I am trying to insert a certain number of points into a certain position
> of a vector with this code:
> x <- seq(1:10909)
> x1 <- c(13112-10909)
> spect1 <- rnorm(13112)
> interpol <- approx(x,spect1,xout=c(seq(from=1, by=((10909 - 1)/(x1 -
> 1)), length.out=x1)))
> pos <- round(interpol$x,0)
> intensities <- interpol$y

Please provide reproducible code that does not give an error.

>
> spect2 <- insert(spect1,ats=pos,values=intensities)

Is this the famous insert() in R.utils? Please give your sessionInfo() to help others see what you are using. I repeat, please provide us with sessionInfo().

>
> "interpol" object is the result of interpoling the missing x values with
> respect to spect1. "pos" object is a vector with the indexes where the
> values are to be placed (it is the rounded values of interpol$x) and
> "intensities" is a vector with the values to be inserted. I try to
> insert the values of "intensities" into the positions specified by "pos"
> in the "x" vector using the insert() functions as shown in the code I
> paste, but I get this error:
>
> Error in list("insert(spect1, ats = pos, values = intensities)" =
> <environment>, :
>
> [2008-02-20 11:36:28] Exception: Argument 'ats' and argument 'values'
> has different lengths: 2203 != 1
> at throw(Exception(...))
> at throw.default("Argument 'ats' and argument 'values' has different
> lengths: ", length(ats), " != ", length(values))
> at throw("Argument 'ats' and argument 'values' has different lengths:
> ", length(ats), " != ", length(values))
> at insert.default(spect1, ats = pos, values = intensities)
> at insert(spect1, ats = pos, values = intensities)
>
> Can anyone help me on how can I solve it? I know that "pos" and
> "intensities" have the same length, so I don't know why I get this
> error. Any ideas will be welcome.

I challenge that claim, because one of the first assertions insert() (of R.utils) does is:

   if (length(ats) != length(values))

       throw("Argument 'ats' and argument 'values' has different lengths: ",
           length(ats), " != ", length(values))

Do the following before you call insert() to troubleshoot your data:

str(spect1)
str(pos)
str(intensities)

/Henrik

> 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.
>



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. Received on Wed 20 Feb 2008 - 11:31:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 21 Feb 2008 - 14:00:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive