I'm preparing a dataset for use with the lme4-package, and I seem to have sinned on one (probably all) of the principles of tidy data.
The dataset looks something like this (actual set has ~ 250 observations):
tribble(
~ID, ~test1, ~randomvar, ~test2,
1, "result1", 2, NA,
2, "result1", 1, "result2",
3, "result1", 4, NA
)
What I need to do is copy every observation where the value of test1 AND test2 is not NA while retaining all other values in the row and inserting them into the same data frame. Basically, copy and paste all rows where the values of two variables are equal to !is.na. I've had a look in R4DS but I can't seem to find a suitable solution for this particular type of mess, although it might just be that I haven't figured out exactly how spread() and gather() works...