Witold Eryk Wolski
2004-Oct-30 22:20 UTC
[R] How to add values to an array at any position.
Hi,
How to add values to an array at any position.
Asking because of the following:
e.g.
y<-c(0.1,NaN,0.2,NaN) #or data frame
x<-na.omit(y)
take some columns from x and
do some computation with functions which do not allow NaN 's.
After the computing add NaN's at positions stored in
attr(x,"na.action")
of the result vector.
/E
--
Dipl. bio-chem. Witold Eryk Wolski
MPI-Moleculare Genetic
Ihnestrasse 63-73 14195 Berlin
tel: 0049-30-83875219 __("< _
http://www.molgen.mpg.de/~wolski \__/ 'v'
http://r4proteomics.sourceforge.net || / \
mail: witek96 at users.sourceforge.net ^^ m m
wolski at molgen.mpg.de
Gabor Grothendieck
2004-Oct-30 22:42 UTC
[R] How to add values to an array at any position.
Witold Eryk Wolski <wolski <at> molgen.mpg.de> writes: : : Hi, : : How to add values to an array at any position. : Asking because of the following: : e.g. : : y<-c(0.1,NaN,0.2,NaN) #or data frame : : x<-na.omit(y) : : take some columns from x and : do some computation with functions which do not allow NaN 's. : : After the computing add NaN's at positions stored in : attr(x,"na.action") : of the result vector. The following adds one to each element of x and reinserts them into y: y[-attr(x,"na.action")] <- x+1
Witold Eryk Wolski <wolski at molgen.mpg.de> writes:> Hi, > > How to add values to an array at any position. > Asking because of the following: > e.g. > > y<-c(0.1,NaN,0.2,NaN) #or data frame > > > x<-na.omit(y) > > take some columns from x and > do some computation with functions which do not allow NaN 's. > > After the computing add NaN's at positions stored in > attr(x,"na.action") > of the result vector.You mean, something like ix <- attr(x, "na.action") newres <- c(res,rep(NA,length(ix))) # just to get size and mode right newres[ix] <- NA newres[-ix] <- res -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907