-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
data_to_long()
did not work with labelled data frames
#498
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
strengejacke
commented
May 7, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem:
data(efc, package = "datawizard")
x1 <- datawizard::data_filter(efc, 1:10)
x2 <- datawizard::data_filter(efc, 21:40)
str(x1)
#> 'data.frame': 10 obs. of 5 variables:
#> $ c12hour : num 16 148 70 NA 168 16 161 110 28 40
#> ..- attr(*, "label")= chr "average number of hours of care per week"
#> $ e16sex : num 2 2 2 2 2 2 1 2 2 2
#> ..- attr(*, "label")= chr "elder's gender"
#> ..- attr(*, "labels")= Named num [1:2] 1 2
#> .. ..- attr(*, "names")= chr [1:2] "male" "female"
#> $ e42dep : Factor w/ 4 levels "1","2","3","4": 3 3 3 NA 4 4 4 4 4 4
#> ..- attr(*, "label")= chr "elder's dependency"
#> ..- attr(*, "labels")= Named num [1:4] 1 2 3 4
#> .. ..- attr(*, "names")= chr [1:4] "independent" "slightly dependent" "moderately dependent" "severely dependent"
#> $ c172code: num 2 2 1 2 2 2 2 2 NA 2
#> ..- attr(*, "label")= chr "carer's level of education"
#> ..- attr(*, "labels")= Named num [1:3] 1 2 3
#> .. ..- attr(*, "names")= chr [1:3] "low level of education" "intermediate level of education" "high level of education"
#> $ neg_c_7 : num 12 20 11 10 12 19 15 11 15 10
#> ..- attr(*, "label")= chr "Negative impact with 7 items"
str(x2)
#> 'data.frame': 20 obs. of 5 variables:
#> $ c12hour : num 150 50 18 168 15 168 12 7 35 168 ...
#> ..- attr(*, "label")= chr "average number of hours of care per week"
#> $ e16sex : num 2 1 2 2 2 1 2 1 2 2 ...
#> ..- attr(*, "label")= chr "elder's gender"
#> ..- attr(*, "labels")= Named num [1:2] 1 2
#> .. ..- attr(*, "names")= chr [1:2] "male" "female"
#> $ e42dep : Factor w/ 4 levels "1","2","3","4": 4 3 4 4 3 4 4 2 3 4 ...
#> ..- attr(*, "label")= chr "elder's dependency"
#> ..- attr(*, "labels")= Named num [1:4] 1 2 3 4
#> .. ..- attr(*, "names")= chr [1:4] "independent" "slightly dependent" "moderately dependent" "severely dependent"
#> $ c172code: num 2 2 2 2 2 2 3 2 2 1 ...
#> ..- attr(*, "label")= chr "carer's level of education"
#> ..- attr(*, "labels")= Named num [1:3] 1 2 3
#> .. ..- attr(*, "names")= chr [1:3] "low level of education" "intermediate level of education" "high level of education"
#> $ neg_c_7 : num 11 9 8 14 11 23 NA 11 15 11 ...
#> ..- attr(*, "label")= chr "Negative impact with 7 items"
cbind(x1, x2)
#> Error in data.frame(..., check.names = FALSE): arguments imply differing number of rows: 10, 20
x1 <- efc[1:10, ]
x2 <- efc[21:40, ]
str(x1)
#> 'data.frame': 10 obs. of 5 variables:
#> $ c12hour : num 16 148 70 NA 168 16 161 110 28 40
#> $ e16sex : num 2 2 2 2 2 2 1 2 2 2
#> $ e42dep : Factor w/ 4 levels "1","2","3","4": 3 3 3 NA 4 4 4 4 4 4
#> $ c172code: num 2 2 1 2 2 2 2 2 NA 2
#> $ neg_c_7 : num 12 20 11 10 12 19 15 11 15 10
str(x2)
#> 'data.frame': 20 obs. of 5 variables:
#> $ c12hour : num 150 50 18 168 15 168 12 7 35 168 ...
#> $ e16sex : num 2 1 2 2 2 1 2 1 2 2 ...
#> $ e42dep : Factor w/ 4 levels "1","2","3","4": 4 3 4 4 3 4 4 2 3 4 ...
#> $ c172code: num 2 2 2 2 2 2 3 2 2 1 ...
#> $ neg_c_7 : num 11 9 8 14 11 23 NA 11 15 11 ...
cbind(x1, x2)
#> Warning in data.frame(..., check.names = FALSE): row names were found from a
#> short variable and have been discarded
#> c12hour e16sex e42dep c172code neg_c_7 c12hour e16sex e42dep c172code
#> 1 16 2 3 2 12 150 2 4 2
#> 2 148 2 3 2 20 50 1 3 2
#> 3 70 2 3 1 11 18 2 4 2
#> 4 NA 2 <NA> 2 10 168 2 4 2
#> 5 168 2 4 2 12 15 2 3 2
#> 6 16 2 4 2 19 168 1 4 2
#> 7 161 1 4 2 15 12 2 4 3
#> 8 110 2 4 2 11 7 1 2 2
#> 9 28 2 4 NA 15 35 2 3 2
#> 10 40 2 4 2 10 168 2 4 1
#> 11 16 2 3 2 12 150 1 4 2
#> 12 148 2 3 2 20 168 1 4 1
#> 13 70 2 3 1 11 NA 2 <NA> 2
#> 14 NA 2 <NA> 2 10 119 1 4 2
#> 15 168 2 4 2 12 168 2 4 2
#> 16 16 2 4 2 19 168 1 4 1
#> 17 161 1 4 2 15 168 1 4 2
#> 18 110 2 4 2 11 28 2 2 2
#> 19 28 2 4 NA 15 168 1 4 2
#> 20 40 2 4 2 10 30 2 3 2
#> neg_c_7
#> 1 11
#> 2 9
#> 3 8
#> 4 14
#> 5 11
#> 6 23
#> 7 NA
#> 8 11
#> 9 15
#> 10 11
#> 11 25
#> 12 9
#> 13 15
#> 14 20
#> 15 9
#> 16 10
#> 17 19
#> 18 8
#> 19 17
#> 20 16
Created on 2024-05-07 with reprex v2.1.0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.