I am in a bit of a bind with an R function that I wrote which is producing the titular error, more specifically, "Number of items to replace is not a multiple of replacement length Error". It contains a helper function, "normative_value_lambda()", which works perfectly. I do not know how to modify it so as to eliminate the error.
Please any insights would be very much appreciated. I ran it on a Windows OS with this Example Dataset.
Code
predicted_choices_lambda <- function()
{
predicted_lambda <- array(dim = c(100, 10))
for(row in 1:100)
{
column <- 1
idx <- 1
lambda <- seq(0.5, 5, by = 0.5)
while((column && idx) <= 10)
{
if(normative_value_lambda(row, lambda[idx]) > 0)
predicted_lambda[row][column] <- TRUE
else
predicted_lambda[row][column] <- FALSE
column <- column + 1
idx <- idx + 1
}
}
return (predicted_lambda)
}
normative_value_lambda <- function(trial.index, lambda)
{
win_percent <- as.numeric(gd$percent[gd$trial_index == trial.index])
loss_percent <- 1 - win_percent
win <- as.numeric(gd$gain[gd$trial_index == trial.index])
lose <- as.numeric(gd$loss[gd$trial_index == trial.index])
return ((win * win_percent) + (lambda * lose * loss_percent))
}