I'm trying to write a function code for a clinical test in R. My R skills are quite rusty and I would really appreciate any help with it.
The function I am trying to write takes 31 values (there are 31 questions in the clinical test that a patient fills out). These 31 values are then scored separately (most questions have different ranges), and then combined together to get the weighted average for different parameters.
The scoring ranges:
for Q 1(defined as x1) - multiply the response by 10
for Q 2,6,5,9 - (scored on a scale of 6) score them as
1 - 100
2 - 80
3 - 60
4 - 40
5 - 20
6 - 0.
for Q 3,4,7,8,10,11,12,13,16,17,18 (scored on a scale of 6)
1 - 0
2 - 20
3 - 40
4 - 60
5 - 80
6 - 100
for Q 14, 25, 26, 27, 28, 29, 30 (scored on a scale of 5)
1 - 100
2 - 75
3 - 50
4 - 25
5 - 0
for Q 19,20 (scored on a scale of 5)
1 - 0
2 - 25
3 - 50
4 - 75
5 - 100
for Q 15, 21, 23, 24 (scored on a scale of 4)
1 - 0
2 - 33.3
3 - 66.7
4 - 100
for Q 22
1 - 0
2 - 50
3 -100
qolie31 <- function(x1, x2, x3, ...){
x1a <- x1*10
z <- c(x2, x5, x6, x9)
{for (i in z){
if (i==1){x == 100}
else if(i==2){x == 80}
else if(i==3){x==60}
else if(i==4){x==40}
else if(i==5){x==20}
else (i==6){x==0}
z2 <- x
}
}
My questions:
I've used the ... function on the first line of code to define that I need arguments from x1 to x31. My end goal is not to define them manually from 1 to 31. Please could someone tell me how to define arguments from x1 to x31, without manually writing on there
How do I save the new score in the function, so that I can use that later for analysis?