Does anyone know an easy way to convert all the zero values in a imported csv table into NA's [[alternative HTML version deleted]]
Amit Patel <amitrhelp at yahoo.co.uk> [Tue, Sep 16, 2008 at 03:32:01PM CEST]:> Does anyone know an easy way to convert all the zero values in a imported csv table into NA'sDepends on the data structure you gave your imported table. In a single numeric vector (named, say, vec), the syntax is is.na(vec[vec==0]) <- TRUE -- Johannes H?sing There is something fascinating about science. One gets such wholesale returns of conjecture mailto:johannes at huesing.name from such a trifling investment of fact. http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi")
> > Does anyone know an easy way to convert all the zero values in a > imported csv table into NA's > > Depends on the data structure you gave your imported table. In a > single numeric vector (named, say, vec), the syntax is > > is.na(vec[vec==0]) <- TRUEThat throws errors for me. An alternative is vec[vec==0] <- NA This also works for data frames, e.g. df <- data.frame(a=c(1,2,3,0,3,4,0,5,2), b=c(1,0,0,1,1,0,1,1,0)) df[df==0] <- NA Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:20}}
Perhaps a simpler way might be to use the na argument in read.table. for instance:> read.table( filename, na=0, ...)-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Amit Patel Sent: Tuesday, September 16, 2008 9:32 AM To: r-help at r-project.org Subject: [R] HI Does anyone know an easy way to convert all the zero values in a imported csv table into NA's [[alternative HTML version deleted]] ______________________________________________ R-help at 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. ================================== P Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S. News & World Report (2008). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{dropped:13}}
If you have read the table as a data frame say, DF then the following should work DF[DF==0]<-NA --- On Tue, 16/9/08, Amit Patel <amitrhelp@yahoo.co.uk> wrote: From: Amit Patel <amitrhelp@yahoo.co.uk> Subject: [R] HI To: r-help@r-project.org Date: Tuesday, 16 September, 2008, 7:02 PM Does anyone know an easy way to convert all the zero values in a imported csv table into NA's [[alternative HTML version deleted]] ______________________________________________ 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. Add more friends to your messenger and enjoy! Go to http://in.messenger.yahoo.com/invite/ [[alternative HTML version deleted]]