Yes, thanks a lot! It works fine! Eleni
On Nov 21, 2007 2:03 PM, Ted Harding <[EMAIL PROTECTED]> wrote: > > On 21-Nov-07 11:15:32, Eleni Christodoulou wrote: > > Hi all! > > I am new to R and I would like to ask you the following question: > > How can I substitute the NA values with 0 in a data frame? > > I cannot find a command to check if a value is NA... > > > > Thank you very much! > > Eleni > > As has been said, is.na() is the function which determines > whether something has "value" NA (result=TRUE) or not (result=FALSE). > > is.na() will work nicely with dataframes (also, of course, with > structures such as vectors, matrices and arrays). Example: > > dummy<-data.frame(X1=c(101,102,103,104,NA,106), > X2=c(201,202,203,NA,205,206)) > > dummy > # X1 X2 > #1 101 201 > #2 102 202 > #3 103 203 > #4 104 NA > #5 NA 205 > #6 106 206 > > dummy[is.na(dummy)] <- 0 > > dummy > # X1 X2 > #1 101 201 > #2 102 202 > #3 103 203 > #4 104 0 > #5 0 205 > #6 106 206 > > Hoping this makes it clear! > Ted. > > -------------------------------------------------------------------- > E-Mail: (Ted Harding) <[EMAIL PROTECTED]> > Fax-to-email: +44 (0)870 094 0861 > Date: 21-Nov-07 Time: 12:03:33 > ------------------------------ XFMail ------------------------------ > ______________________________________________ R-help@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.