Skip to content
Prev 299468 / 398503 Next

replacement has length zero

On 2012-07-08 06:57, fabiano wrote:
I don't understand how this relates to a 2-by-7 matrix,
but it's easy to see where your problem with the loop is.
Try this and see if it sheds light:

   hab[1,] <- Hab[habitat==1,1]
   #Error in hab[1, ] <- Hab[habitat == 1, 1] : replacement has length zero

   hab[2,] <- Hab[habitat==2,1]
   #Error in hab[2, ] <- Hab[habitat == 2, 1] :
   number of items to replace is not a multiple of replacement length

Now do:
   Hab[habitat==1,1]    ## how many 1s are in habitat?
   Hab[habitat==2,1]    ## how many 2s are in habitat?

I think that you may have to rethink your approach.

Peter Ehlers