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

joshuaulrich opened this Issue Feb 26, 2015 · 3 comments


None yet
3 participants

joshuaulrich commented Feb 26, 2015

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)
Error in na.locf.xts(s1) : unsupported type

s1 <- xts(c(1,2,NA,4), Sys.Date()+1:4)
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)
2011-09-28 'OK'
2011-09-29 'Fail'
2011-09-30 'Fail'
2011-10-01 'Service'


@joshuaulrich joshuaulrich added the bug label Feb 26, 2015


This comment has been minimized.

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

This comment has been minimized.

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))

joshuaulrich added a commit that referenced this issue Mar 12, 2018

Support character xts in na.locf() and na.omit()
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

Fixes #42.

This comment has been minimized.


joshuaulrich commented Mar 14, 2018

@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