[R] insert() function

Dani Valverde daniel.valverde at uab.cat
Wed Feb 20 11:38:14 CET 2008


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

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

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



More information about the R-help mailing list