The thing I need to do is to replace NA values with 0. But I;m not able to determine how to do it. I'm relative new, pls Help. Malmo -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Adamka <malmo at unitra.sk> writes:> The thing I need to do is to replace NA values with 0. > But I;m not able to determine how to do it.x[is.na(x)] <- 0 -- 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 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> The thing I need to do is to replace NA values with 0. > But I;m not able to determine how to do it.In what sort of structure? A vector?> a <- c(1,2,NA,3,4,NA,5,6,NA) > a[1] 1 2 NA 3 4 NA 5 6 NA> a[!is.na(a)][1] 1 2 3 4 5 6 A list?> a <- list(1,2,3,NA,4,5,NA,6,NA,7) > a[!sapply(a,is.na)][[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 [[4]] [1] 4 [[5]] [1] 5 [[6]] [1] 6 [[7]] [1] 7 Something else? -Jeff -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>Subject: [R] replace >From: Peter Adamka <malmo at unitra.sk> >To: r-help at stat.math.ethz.ch >Content-Transfer-Encoding: 7bit >Date: 11 Oct 2002 18:58:15 +0200 >Mime-Version: 1.0 > >The thing I need to do is to replace NA values with 0. >But I;m not able to determine how to do it. >I'm relative new, pls Help. >MalmoIs this what you wanted? tt <- c(1, 2, NA, NA, 5, NA) tt[is.na(tt)] <- 0 tt now is: tt [1] 1 2 0 0 5 0> > > >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- >r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html >Send "info", "help", or "[un]subscribe" >(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch >_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Following up on my own message, sorry I was just removing NAs, sorry.> A vector? > > a <- c(1,2,NA,3,4,NA,5,6,NA) > > a > [1] 1 2 NA 3 4 NA 5 6 NA> a[is.na(a)] <- 0 > a[1] 1 2 0 3 4 0 5 6 0> A list? > > a <- list(1,2,3,NA,4,5,NA,6,NA,7) > a <- lapply(a,function(x){if(is.na(x))return(0) else(return(x))}) > a[[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 [[4]] [1] 0 [[5]] [1] 4 [[6]] [1] 5 [[7]] [1] 0 [[8]] [1] 6 [[9]] [1] 0 [[10]] [1] 7 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
x[is.na(x)] <- 0 On 11 Oct 2002, Peter Adamka wrote:> The thing I need to do is to replace NA values with 0. > But I;m not able to determine how to do it. > I'm relative new, pls Help. > Malmo > > > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-- 318 Carr Hall bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._