I appreciate your help. I am still a very bigger with a lot of curiosity in R. I do know I must study by myself a lot more, but if you could spare your time, it would be a big help. I spent almost four days with this problem... anyway...
Conditions
There are two parameters.
a: ability
d: difficulty
The initial values of them are zero.
ability <- 0
difficulty <- 0
Both parameters will be repeatedly updated according to the gained response from x, y, and z.
If the response is 1, one will be added to a and one will be subtracted from b based on the previous value.
If the response is 0, one will be subtracted from a and one will be added to b based on the previous value.
if the response is 1: a^ = a + 1, b^ = b - 1
if the response is 0: a^ = a - 1, b^ = b + 1
Now I have a data set below.
x y z
1 0 0
1 1 0
1 1 0
At the end, applying the condition, the results of data (x, y, and z) should be like below:
x: a^ = 3, b^ = -3 [1, 1, 1]
y: a^ = 1, b^ = -1 [0, 1, 1]
z: a^ = -3, b^ = 3 [0, 0, 0]
To achieve this in R, I wrote the codes like below with very limited knowledge, but I only got a failure with warning messages.
ability <- 0
difficulty <- 0
res <- apply(data, 2, function(x, a = ability, d = difficulty){
for (i in 1:3)
if (x == 1){
a[i] <- a+1
d[i] <- d-1
}
else {
a[i] <- a-1
d[i] <- d+1
}
return(c(x, a, d))
}
)
The warning messages I got are below:
1: In if (x == 1) { ...
the condition has length > 1 and only the first element will be used
I feel like I must use "ifelse" statement, but I do know how to apply it to this case (return data format).
I appreciate your help. Thank you in advance.