How to solve 'number of items to replace is not a multiple of replacement length' warning

I am getting the following warning when trying to run the code below:
In go.IA[i] <- ifelse(orr.IA >= gorule.IA, 1, 0) :
number of items to replace is not a multiple of replacement length

I've seen a number of discussions on this warning and so understand why I am getting it, but not how to solve it when it appears in an ifelse statement. Would appreciate any help!

op_char_IA <- function(truth, n, stoprule, gorule, truth.IA, n.IA, stoprule.IA, gorule.IA){
stop <- consider <- go <- NULL
stop.IA <- consider.IA <- go.IA <- NULL
nsim <- 10000

for(i in 1:nsim){
orr <- rbinom(1, n, truth)
orr.IA <- orr[1:n.IA]
go.IA[i] <- ifelse(orr.IA>=gorule.IA, 1, 0)
consider.IA[i] <- ifelse(orr.IA<gorule.IA & orr.IA>stoprule.IA,1,0)
stop.IA[i] <- ifelse(orr.IA<=stoprule.IA,1,0)

go[i] <- ifelse(orr>=gorule & go.IA[i]==1, 1, 0)
consider[i] <- ifelse(orr<gorule & orr>stoprule,1,0)
stop[i] <- ifelse(orr<=stoprule | stop.IA[i]==1 ,1,0)

meango <- mean(go)
meanstop <- mean(stop)
meancons <- mean(consider)

out <- c(meango, meanstop, meancons)
names(out) <- c("Go", "Stop", "Consider")

op_char_IA(truth=.40, n=35,stoprule=16, gorule=17 ,truth.IA=.40, n.IA=17, stoprule.IA=5, gorule.IA=6)

on the right side of <- you have something that will generate a sequence of 1's and 0's

these multiple 1s and 0s cant fit into one element of a vector
to be able to do such a thing; the element go.IA[i] would have to be a list
consider this example

x <- NULL

x[1] <- 1
x[2] <- 2
x[3] <- 3:4
x # we lost the 4 because it wont fit

#possible but changes x from a vector of numbers to a list containing numbers and vectors of numbers
x[3] <- list(3:4)

Thanks for your reply. I will have a look into this.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.