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

Exclusion must be turned off for conditionalTransform #153

Closed
persephonet opened this issue Oct 31, 2017 · 1 comment · Fixed by #160
Closed

Exclusion must be turned off for conditionalTransform #153

persephonet opened this issue Oct 31, 2017 · 1 comment · Fixed by #160
Assignees

Comments

@persephonet
Copy link
Contributor

persephonet commented Oct 31, 2017

If rows are excluded during and you try to do a conditionalTransform, you get:

[crunch] > ds$Tier1_1 <- conditionalTransform((((ds$q7a$q7a_3 %in% 1 | ds$q7a$q7a_8 %in% 1) & (ds$q7b$q7b_2 %in% 1 | ds$q7b$q7b_4 %in% 1)) | 
+     ((ds$q7a$q7a_4 %in% 1 | ds$q7a$q7a_9 %in% 1 | ds$q7a$q7a_10 %in% 1 | ds$q7a$q7a_11 %in% 1 | ds$q7a$q7a_12 %in% 1) & ((ds$q7a_NEWa %in% 1 | ds$q7a_NEWb %in% 1) & (ds$q7b$q7b_2 %in% 1 | ds$q7b$q7b_4 %in% 1))) | 
+     (ds$q8_aNEW_2$q8_aNEW_2_5 %in% 1 & (ds$q8_b$q8_b_2 %in% 1 | ds$q8_b$q8_b_4 %in% 1)) | 
+     (ds$p1 %in% 1 & (ds$p2m$p2m_2 %in% 1 | ds$p2m$p2m_5 %in% 1))) ~ 'True',
+     else_condition = 'False',
+     categories = c(Category(name='True', id=1, numeric_value=1, missing=FALSE),
+         Category(name='False', id=2, numeric_value=2, missing=FALSE)),
+     type='categorical',
+     name="Group 1 Experience and contacted (SW or local water board)")
Error: replacement has 28145 rows, data has 21299

It would be convenient to be able to do conditionalTransform with an exclusion on.

@jonkeane
Copy link
Contributor

jonkeane commented Nov 8, 2017

I've added tests for datasets with exclusions. I wasn't able to reproduce the exact error you saw here, but I was able to replicate other similar errors, and made a change that should prevent them in the future, once #160 is merged.

I'm not sure the context around this specific use of conditionalTransformation, but I would like to point out that if the result of your conditional transform is a categorical, you will almost always be better off using makeCaseVariable instead of conditionalTransformation. In this case, you should be able to use the following:

ds$Tier1_1 <- makeCaseVariable("True" = (((ds$q7a$q7a_3 %in% 1 | ds$q7a$q7a_8 %in% 1) & (ds$q7b$q7b_2 %in% 1 | ds$q7b$q7b_4 %in% 1)) |
                             ((ds$q7a$q7a_4 %in% 1 | ds$q7a$q7a_9 %in% 1 | ds$q7a$q7a_10 %in% 1 | ds$q7a$q7a_11 %in% 1 | ds$q7a$q7a_12 %in% 1) & ((ds$q7a_NEWa %in% 1 | ds$q7a_NEWb %in% 1) & (ds$q7b$q7b_2 %in% 1 | ds$q7b$q7b_4 %in% 1))) |
                             (ds$q8_aNEW_2$q8_aNEW_2_5 %in% 1 & (ds$q8_b$q8_b_2 %in% 1 | ds$q8_b$q8_b_4 %in% 1)) |
                             (ds$p1 %in% 1 & (ds$p2m$p2m_2 %in% 1 | ds$p2m$p2m_5 %in% 1))),
                 "False" = "else",
                 name = "Group 1 Experience and contacted (SW or local water board)")

Let me know if this makeCaseVariable version doesn't work.

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

Successfully merging a pull request may close this issue.

2 participants