Error in selbst & anz != 3 : operations are possible only for numeric, logical or complex types

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Error in selbst & anz != 3 : operations are possible only for numeric, logical or complex types

Valeriya.
Need to create a loop that first run the function for all 400 nodes AanzLebendNachbarn(g, i)
 and then the function NaechsteRunde(V[i], ALN) in addition i need to create a vector which fits in the solutions from this functions.
that is the code for the loop:
lt <- c()
for(i in 400){
 ALN <-anzLebendNachbarn(g, i)
 NR <- NaechsteRunde(V[i], ALN)
 NR(which(is.null(NR)==TRUE)) <- 0
 print(NR)
 lt <-c(lt, NR)
}

l=length(lt)
print(l)

and then i return this error message:

Error in selbst & anz != 3 :    operations are possible only for numeric, logical or complex types

so i changed the definition in my function into == and = and nothing had changed, but the function it selfs run perfectly and gives the right solution:
anzLebendNachbarn = function (g,nr) {
  neig <-neighbors(g, nr)
  lv = c()
  for(i in neig){
    ifelse(   V[i] == "TRUE",
              lv <-c(lv, i),"")

  }
  l=length(lv)
  print(l)
}
anzLebendNachbarn(g, 191)

#Aufgabe5
NaechsteRunde = function(selbst,anz){
 
  if ( selbst & anz = 3) {
    result <- "TRUE"
  }
  else if (selbst & anz<2) {
    result <- "FALSE"
  }
  else if (selbst& anz>2||3){
    result <- "TRUE"
  }
  else if (selbst & anz>3){
    result <- "FALSE"
  }
  return(result)

}
NaechsteRunde(1,3)
 That are the Function were i implement the 4 rules of the  Conway's Game of Life.

I hope someone sees the mistake i made.