This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error in my R code

Can somebody help me with my error pls?

Agent1 <- data.frame( AgentNo = 1,
                      State = "E",
                      Mixing = runif(1,0,1))

nPOP1 <- 10
# create a population of Agents

for(i in 2:nPOP1){
  Agent2 <- data.frame( AgentNo = i,
                        State = "S",
                        Mixing = runif(1,0,1))
  Agent1 <-rbind(Agent1, Agent2)
}

#Part 2
for (i in 1:nPOP1){
  #Determine if they like to meet others 
  Mix1 <- Agent1$Mixing [i ]
  # how many agents will they meet?
  Meet1 <- round(Mix1*3,0)
  # Grab the agents they will meet
  Meet2 <- sample( 1:nPOP1, Meet1, replace = TRUE)

  for( j in 1:length(Meet2)){
    #Grab who they will meet
    Meet1a <- Agent1[ Meet2[j], ]
    #If exposed change state
    if (Meet1a$State == "E" ) {
      Agent1$State [1] <- "E"
    }
  }
}



Error in if (Meet1a$State == "E") { : 
  missing value where TRUE/FALSE needed

What should i do with that?

r

Can you clarify how this is related to bioinformatics? If you are looking for help with plain R code then this is not the correct forum. You should post over in stackoverflow.

Hello balintkovacs.elte!

We believe that this post does not fit the main topic of this site.

This is not bioinformatics-related. Also asked before at StackExchange: https://stackoverflow.com/questions/7355187/error-in-if-while-condition-missing-value-where-true-false-needed

You have NAs in your data.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

If you post something then please for the future provide example data, e.g. via dput().

0 answers

No answers yet.

Log in to answer this question.