Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R-Forge #1603] Can't use na.locf() on character data #42

Closed
joshuaulrich opened this issue Feb 26, 2015 · 3 comments
Closed

[R-Forge #1603] Can't use na.locf() on character data #42

joshuaulrich opened this issue Feb 26, 2015 · 3 comments
Labels

Comments

@joshuaulrich
Copy link
Owner

Submitted by: Ken Williams (@kenahoo)
Assigned to: Nobody
R-Forge link

na.locf() seems to fail on xts objects containing character data:

s1 <- xts(c('OK', 'Fail', NA, 'Service'), Sys.Date()+1:4)
na.locf(s1)
Error in na.locf.xts(s1) : unsupported type

s1 <- xts(c(1,2,NA,4), Sys.Date()+1:4)
na.locf(s1)
[,1]
2011-09-28 1
2011-09-29 2
2011-09-30 2
2011-10-01 4

I can use na.locf.default() as a workaround, I don't seem to lose any fidelity in the process:

s1 <- xts(c('OK', 'Fail', NA, 'Service'), Sys.Date()+1:4)
na.locf.default(s1)
[,1]
2011-09-28 'OK'
2011-09-29 'Fail'
2011-09-30 'Fail'
2011-10-01 'Service'

-Ken

@SamoPP
Copy link

SamoPP commented Feb 7, 2017

Also seems that na.omit fails on all character data:

> na.omit(xts(c("a", "b", "c", NA, "d"), as.Date(1:5)))
Error in na.omit.xts(xts(c("a", "b", "c", NA, "d"), as.Date(1:5))) : 
  unsupported type

@Masutani
Copy link

Masutani commented Nov 28, 2017

xout option for na.locf / na.locf.default cannot work for character data (xts/zoo) .
Failed with "zero non-NA points" error in approx .

I found the process is fine until reaching to 26 line in na.approx
objectm <- merge(object.x, zoo(, xout))
https://github.com/cran/zoo/blob/master/R/na.approx.R

joshuaulrich added a commit that referenced this issue Mar 12, 2018
Update na.locf() unit tests to run over the 4 major atomic types.

Note that the 'xout' test does not currently run on character data
because merging a character xts with a zero-width xts return a numeric
result. This happens because all zero-width xts objects are numeric,
and merge.xts converts all inputs to a common type.

Add branch to handle character xts objects to 3 functions: firstNonNA,
na_locf, and na_omit_xts. Nothing too special, just copied a branch
for another type and changed the accessors to the necessary string
versions.

Fixes #42.
@joshuaulrich
Copy link
Owner Author

@kenahoo, I hope "better late than never" applies in this case!

I didn't address the n-way merge issue on character xts because I have some significant changes to the merge C code that I would like to incorporate first.

@joshuaulrich joshuaulrich added this to the Release 0.10-2 milestone Mar 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants