I have this little data.frame http://dl.dropbox.com/u/102669/nanotna.rdata Two column contains NA, so the best thing to do is use na.locf function (with fromLast = T) But locf function doesn't work because NA in my data.frame are not recognized as real NA. Is there a way to substitute fake NA with real NA? In this case na.locf function should work Thank you
On 18-03-2013, at 16:49, Pete <freerisk3 at gmail.com> wrote:> > I have this little data.frame > > http://dl.dropbox.com/u/102669/nanotna.rdata > > Two column contains NA, so the best thing to do is use na.locf function (with > fromLast = T) > > But locf function doesn't work because NA in my data.frame are not recognized as > real NA. > > Is there a way to substitute fake NA with real NA? In this case na.locf function > should work >Your data are all characters. Do str(db) to see that. What is probably supposed to be numeric is also character, Somehow you have managed to read in data that R thinks is all chr. Your NA are "NA" in reality: a character string "NA". You will have to review the method you used to get the data into R. And make sure that what you want to be numeric is indeed numeric. Then you can start to think about doing something about the NA's. Berend
Use lag.xts:
R> lag(x,-1)
aaa bbb ccc ddd
2001-01-02 181.1751 243.24 1689.10 267.15
2001-01-03 181.6126 242.09 1737.86 267.10
2001-01-04 NA NA NA NA
Note that the sign of k is different for lag.xts than lag.zoo (and lag.default).
R> lag(as.zoo(x),-1)
aaa bbb ccc ddd
2001-01-03 179.7061 239.11 1712.6 271.10
2001-01-04 181.1751 243.24 1689.1 267.15
Best,
--
Joshua Ulrich | about.me/joshuaulrich
FOSS Trading | www.fosstrading.com
R/Finance 2013: Applied Finance with R | www.RinFinance.com
On Sun, Apr 7, 2013 at 8:34 AM, Michela <freerisk3 at gmail.com>
wrote:> i have an xts object:
>
> aaa bbb ccc ddd
> 2001-01-02 179.7061 239.11 1712.60 271.10
> 2001-01-03 181.1751 243.24 1689.10 267.15
> 2001-01-04 181.6126 242.09 1737.86 267.10
>
> i simply want translate upward all the values
> So values in first row are lost. All others traslate upward
>
> In my example, xts object should become:
>
> aaa bbb ccc ddd
> 2001-01-02 181.1751 243.24 1689.10 267.15
> 2001-01-03 181.6126 242.09 1737.86 267.10
> 2001-01-04 NA NA NA NA
>
> Any idea how to do this upward translation?
>
> thanks
>
> ______________________________________________
> 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.