[R] insert() function
Henrik Bengtsson
hb at stat.berkeley.edu
Wed Feb 20 12:27:32 CET 2008
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.
>
More information about the R-help
mailing list