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

replace_na() does not work for matrices #1511

Closed
privefl opened this issue Aug 4, 2023 · 4 comments
Closed

replace_na() does not work for matrices #1511

privefl opened this issue Aug 4, 2023 · 4 comments

Comments

@privefl
Copy link

privefl commented Aug 4, 2023

x <- c(0:2, NA)
tidyr::replace_na(x, 3)
## [1] 0 1 2 3
tidyr::replace_na(matrix(x, 2), 3)
##      [,1] [,2]
## [1,]    0    2
## [2,]    1   NA

I have {tidyr} v1.2.1.

@hadley
Copy link
Member

hadley commented Nov 1, 2023

Yes, it only works with data frames or vectors, sorry.

@hadley hadley closed this as completed Nov 1, 2023
@privefl
Copy link
Author

privefl commented Nov 1, 2023

Yes, but a matrix is also a vector, so.. And I get a matrix as output, so I would expect this to have worked somehow.
Maybe an error/warning would be nice.

@hadley
Copy link
Member

hadley commented Nov 2, 2023

I wouldn't say a matrix is a vector because vectors are 1d. Behind the scenes matrices are made up of vectors, but that's an implementation detail.

@jranke
Copy link

jranke commented Feb 14, 2025

There used to be a replace_na function somewhere that supported matrices. Silently not doing anything for matrices was not what I expected. I think a warning would be warranted.

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

3 participants