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

adding NA values to a factor #250

Closed
bczucz opened this issue Feb 11, 2020 · 1 comment
Closed

adding NA values to a factor #250

bczucz opened this issue Feb 11, 2020 · 1 comment

Comments

@bczucz
Copy link

bczucz commented Feb 11, 2020

As a part of the improved NA handling I would be very glad for a simpler & cleaner way for adding new NA values to a factor.

> x <- factor(1:3)
> fct_c(NA, x)
Error: All elements of `...` must be factors

The following works, but it looks less "tidy":

> fct_c(factor(NA), x)
[1] <NA> 1    2    3   
Levels: 1 2 3

Thanks!
Balint

@hadley
Copy link
Member

hadley commented Feb 21, 2020

You can do that (and much more) with vctrs::vec_c():

vctrs::vec_c(NA, factor(1:3))
#> [1] <NA> 1    2    3   
#> Levels: 1 2 3

Created on 2020-02-21 by the reprex package (v0.3.0)

I think at some point we'll eventually retire fct_c() in favour of this function.

@hadley hadley closed this as completed Feb 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants