Hi Michael,
Sorry! You are right. That was OP's code, which I cut and paste without noticing it. To Scoyoc: You can also try this: dat1 <-data.frame(A, B, C, D, E ) dat1new<-dat1[,2:3] dat1new[is.na(dat1new)]<-0 dat1[,2:3]<-dat1new dat1 # A B C D E #1 1 6 0 16 21 #2 2 7 0 17 NA #3 3 0 13 18 NA #4 4 0 14 19 NA #5 5 0 15 20 25 A.K. ----- Original Message ----- From: R. Michael Weylandt <michael.weyla...@gmail.com> To: arun <smartpink...@yahoo.com> Cc: scoyoc <sco...@gmail.com>; R help <r-help@r-project.org> Sent: Thursday, October 11, 2012 7:04 PM Subject: Re: [R] Changing NA to 0 in selected columns of a dataframe On Thu, Oct 11, 2012 at 11:58 PM, arun <smartpink...@yahoo.com> wrote: > Hi, > Try this: > dat1 = as.data.frame ( cbind ( A, B, C, D, E ) ) No. Do not try this. It is a Very Bad Thing to use as.data.frame(cbind(...)) instead of data.frame(...) for reasons I've mentioned before on this list. In short, cbind() forces all its arguments to a single mode, thereby missing the entire point of a data frame. Cheers, Michael ______________________________________________ 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.