-
Notifications
You must be signed in to change notification settings - Fork 130
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
Base scale not working with tibble #762
Comments
library(tibble)
iris <- as_tibble(iris)
scale <- scale(iris[1:3])
class(scale)
#> [1] "matrix"
iris[1:3] <- as.data.frame(scale)
head(iris)
#> # A tibble: 6 x 5
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> <dbl> <dbl> <dbl> <dbl> <fct>
#> 1 -0.898 1.02 -1.34 0.2 setosa
#> 2 -1.14 -0.132 -1.34 0.2 setosa
#> 3 -1.38 0.327 -1.39 0.2 setosa
#> 4 -1.50 0.0979 -1.28 0.2 setosa
#> 5 -1.02 1.25 -1.34 0.2 setosa
#> 6 -0.535 1.93 -1.17 0.4 setosa Created on 2020-04-15 by the reprex package (v0.3.0) |
Fixed by rolling Tibble package version back to 2.1.3 |
See https://tibble.tidyverse.org/dev/articles/invariants.html for details. What is your use case? |
Standardizing (mean 0, sd =1) multiple columns at once before aggregating to create an index measure. Data science/ analytics |
Are you calling |
calling from a script |
I wonder if this is common enough to warrant a compatibility fix that will be converted to an error later on. We would disallow assignment of columns if the right-hand side is a matrix, and issue a deprecation warning. To get rid of the warning, users would need to use Would that help your use case? |
Alternatively, we could also revert to previous behavior and ask users to wrap in a list if they really want a matrix column. |
I'm no expert, but for my case, the previous behavior is desirable. The tibble is "broken" after I execute the same command in the latest version, sorting returns an error: |
Thanks. Now: library(tibble)
iris <- as_tibble(iris)
iris[1:3] <- as.data.frame(scale(iris[1:3]))
head(iris)
#> # A tibble: 6 x 5
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> <dbl> <dbl> <dbl> <dbl> <fct>
#> 1 -0.898 1.02 -1.34 0.2 setosa
#> 2 -1.14 -0.132 -1.34 0.2 setosa
#> 3 -1.38 0.327 -1.39 0.2 setosa
#> 4 -1.50 0.0979 -1.28 0.2 setosa
#> 5 -1.02 1.25 -1.34 0.2 setosa
#> 6 -0.535 1.93 -1.17 0.4 setosa Created on 2020-04-16 by the reprex package (v0.3.0) Added a section to https://tibble.tidyverse.org/dev/articles/invariants.html#column-subassignment-x-j-a. |
Thanks! |
oh my gosh thanks so much! |
tibble 3.0.1 - `[<-.tbl_df()` coerces matrices to data frames (#762). - Use delayed import for cli to work around unload problems in downstream packages (#754). - More soft-deprecation warnings are actually visible. - If `.name_repair` is a function, no repair messages are shown (#763). - Remove superseded signal for `as_tibble.list()`, because `as_tibble_row()` only works for size 1. - `as_tibble(validate = )` now always triggers a deprecation warning. - Subsetting and subassignment of rows with one-column matrices work again, with a deprecation warning (#760). - Attempts to update a tibble row with an atomic vector give a clearer error message. Recycling message for subassignment appears only if target size is != 1. - Tweak title of "Invariants" vignette.
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary. |
Applying base scale to multiple columns in a tibble results in an incorrectly scaled output and breaks the tibble on sort. Fresh windows, fresh and latest R/RStudio, latest tidyverse.
The text was updated successfully, but these errors were encountered: