-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Modulation of appending/overwriting standardized variables in standardize()
not working
#31
Comments
@mattansb @DominiqueMakowski If we change anything here, we need to be explicit in setting arguments in our other packages where we call |
expected behaviour (from my point of view): d <- iris[1:4, ]
# this should only return the two standardized variables, including suffix
sjmisc::std(d, Sepal.Length, Sepal.Width, append = FALSE, suffix = "_z")
#> Sepal.Length_z Sepal.Width_z
#> 1 1.2402159 1.3887301
#> 2 0.3382407 -0.9258201
#> 3 -0.5637345 0.0000000
#> 4 -1.0147221 -0.4629100
# this should return the original data frame and column bound
# the standardized variables, including suffix
sjmisc::std(d, Sepal.Length, Sepal.Width, append = TRUE, suffix = "_z")
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length_z
#> 1 5.1 3.5 1.4 0.2 setosa 1.2402159
#> 2 4.9 3.0 1.4 0.2 setosa 0.3382407
#> 3 4.7 3.2 1.3 0.2 setosa -0.5637345
#> 4 4.6 3.1 1.5 0.2 setosa -1.0147221
#> Sepal.Width_z
#> 1 1.3887301
#> 2 -0.9258201
#> 3 0.0000000
#> 4 -0.4629100
# this should only return the standardized variables, w/o suffix
sjmisc::std(d, Sepal.Length, Sepal.Width, append = FALSE, suffix = NULL)
#> Sepal.Length Sepal.Width
#> 1 1.2402159 1.3887301
#> 2 0.3382407 -0.9258201
#> 3 -0.5637345 0.0000000
#> 4 -1.0147221 -0.4629100
# suffix = NULL doesn't work here, need "" to overwrite
# this should return the original data frame and the the standardized variables
# *overwrite* the related variables
sjmisc::std(d, Sepal.Length, Sepal.Width, append = TRUE, suffix = "")
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 1.2402159 1.3887301 1.4 0.2 setosa
#> 2 0.3382407 -0.9258201 1.4 0.2 setosa
#> 3 -0.5637345 0.0000000 1.3 0.2 setosa
#> 4 -1.0147221 -0.4629100 1.5 0.2 setosa Created on 2021-11-04 by the reprex package (v2.0.1) |
We could reduce the functionality to either overwrite or append standardized variables, then we would need only |
See #32 |
Not sure I follow - are we talking about dropping the If so, that sounds fine to me. |
We can have two options: either, drop |
Mmmh in this light I would say that we only keep
The only option not available out-of-the-box is to rename & replace, but it's fine i think since i hardly see a common usecase for that and that just standardizing and renaming in a different step is a minor added trouble. |
Why append instead of suffix? How can be define the suffix then? |
because append suggests that it will append the standardized data to the other data, which is the primary effect (the suffix is just a "side-effect") |
Ah, you mean |
yep |
d <- iris[1:4, ]
# overwrite
datawizard::standardise(d, select = c("Sepal.Length", "Sepal.Width"))
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 1.2402159 1.3887301 1.4 0.2 setosa
#> 2 0.3382407 -0.9258201 1.4 0.2 setosa
#> 3 -0.5637345 0.0000000 1.3 0.2 setosa
#> 4 -1.0147221 -0.4629100 1.5 0.2 setosa
# append
datawizard::standardise(d, select = c("Sepal.Length", "Sepal.Width"), append = TRUE)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length_z
#> 1 5.1 3.5 1.4 0.2 setosa 1.2402159
#> 2 4.9 3.0 1.4 0.2 setosa 0.3382407
#> 3 4.7 3.2 1.3 0.2 setosa -0.5637345
#> 4 4.6 3.1 1.5 0.2 setosa -1.0147221
#> Sepal.Width_z
#> 1 1.3887301
#> 2 -0.9258201
#> 3 0.0000000
#> 4 -0.4629100
# append, suffix
datawizard::standardise(d, select = c("Sepal.Length", "Sepal.Width"), append = "_std")
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length_std
#> 1 5.1 3.5 1.4 0.2 setosa 1.2402159
#> 2 4.9 3.0 1.4 0.2 setosa 0.3382407
#> 3 4.7 3.2 1.3 0.2 setosa -0.5637345
#> 4 4.6 3.1 1.5 0.2 setosa -1.0147221
#> Sepal.Width_std
#> 1 1.3887301
#> 2 -0.9258201
#> 3 0.0000000
#> 4 -0.4629100 Created on 2021-11-04 by the reprex package (v2.0.1) |
Related to #30
Created on 2021-11-04 by the reprex package (v2.0.1)
The text was updated successfully, but these errors were encountered: