I have a dataframe with patients that have answered twice in same questionnaire in couple of years.
Now I need to calculate how many patient developed problem, how many improved and how many maintained having problems. The answers are in scale 1-6 where <3
is no problem, 3-4.75
is sometimes problem and >= 5
is problems.
I have merged these two dataframe to one and tried to calculate difference by coding
dat5$noproblem = ((dat5$sleepProblems.x)<3)-((dat5$sleepProblems.y)<3)
but I only get a dataframe there is zero and minus 1 and which dimension is NULL. I tried do the same with
diff((dat5$sleepProblems.x<3) - lag((dat5$sleepProblems.y<3)))
but I still get just list of different values.
How I can get the amount of patients?
(Sorry for unclear description)
EDIT: Note that organisation is changed from real number to x in order to maintain the privacy of the individuals
structure(list(Organisation = c("XXX", "XXX", "XXX",
"XXX", "XXX"), VAR066_1 = c(3L, 2L, 3L, 3L, 2L), VAR066_3 = c(3L,
2L, 5L, 2L, 2L), VAR066_5 = c(3L, 4L, 5L, 3L, 2L), VAR066_6 = c(2L,
2L, 5L, 2L, 2L), sleepProblems.x = c(2.75, 2.5, 4.5, 2.5, 2),
VAR074_1 = c(3L, 2L, 3L, 3L, 3L), VAR074_3 = c(2L, 2L, 4L,
3L, 4L), VAR074_5 = c(2L, 2L, 3L, 3L, 3L), VAR074_6 = c(3L,
2L, 3L, 2L, 3L), sleepProblems.y = c(2.5, 2, 3.25, 2.75,
3.25), sleepingproblems = c(0L, 0L, 0L, 0L, 1L), noproblem = c(0L,
0L, 0L, 0L, 1L)), row.names = c(NA, 5L), class = "data.frame")