For your first question, I believe that dat[dat==-9]=NA
should do the trick For your second, are you dates in the Date() format? If not, try ?Date Once you get them in Date format, then you can simply subtract them d1 = as.Date('20090604',format="%Y%m%d") d2 = as.Date('20080604',format="%Y%m%d") d1-d2 Time difference of 365 days On Thu, Nov 26, 2009 at 12:30 PM, Val <valkr...@gmail.com> wrote: > Hi all, > > > > Assume that I have a data set (“xcv”) with several variables and some of > the variables have a missing observation represented by -9 as shown below. > I want to exclude these observations from the analysis ( as a NA). Is > there a command that I can do it for the entire data set rather than one by > one for each variable ( tmp <- xcv[xcv$v1 != -9, ]) > > > > V1 v2 v3 v4 > > 11 23 14 -9 > > 12 -9 21 3 > > -9 30 41 25 > > 15 07 -9 10 > > > > and I want the results as follows > > > > V1 v2 v3 v4 > > 11 23 14 NA > > 12 NA 21 3 > > NA 30 41 25 > > 15 07 NA 10 > > > > > > The second question is I want to calculate the number of days between two > dates > > Start end number of days > > 20020626 20020805 40 > > 20030101 20030421 110 > > > > How do I do it in R? > > > Thanks in advance > > [[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. > > ______________________________________________ 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.