user2945829
user2945829

Reputation: 13

My programme is showing the following error: 'argument 'length.out' must be of length 1'. I do not think I have made any mistake

I am creating a data for a model in ecology which is called as random fraction model. The programme for the model:

    RelAbund<-randomfraction(3,1000)

Its output is:

    RelAbund
      [,1]        [,2]
    [1,] 0.6083835 0.004510276
    [2,] 0.2792227 0.003305510
    [3,] 0.1123938 0.002514014

Now I want to create data using the first column of this matrix. I am storing this data in a list called 'Data'. It is a list of vectors. The vectors contain consecutive +ve numbers. e.g. vector1 is (1,2,3,4,5) vector2 is(6,7,8,9,10,11,12,13) & so on. Now the programme I have written to create the data is as follows:

    CreateData<-function(nind,nspec)  
    RelAbund<-randomfraction(nspec,1000)                                                                                      
    Data<-list()
    Datavector<-c()
    individuals<-c(0)
    for(ii in 1:nspec-1){
    **individuals<-seq(length.out=RelAbund[ii,1]*nind,from=tail(individuals,n=1)+1,by=1)** 
    Data<-lappend(Data,individuals)
    }
    Datavector<-seq(length=nind-(tail(tail(Data,n=1),n=1)),from=tail(tail(Data,n=1),n=1)+1,by=1)
    Data<-lappend(Data,Datavector)
    return(Data)
    }

The starred line is showing error:

Error is as follows:

    Error in seq.default(length.out = RelAbund[ii, 1] * nind, from = tail(individuals,  : argument 'length.out' must be of length 1

nind is an integer. Acc to me the argument length.out is already of length 1. Then why is it showing this error??

Upvotes: 0

Views: 4601

Answers (1)

kith
kith

Reputation: 5566

Are you sure you didn't mean

for(ii in 1:(nspec-1)){
  ...
}

instead of

for(ii in 1:nspec-1){
  ...
}

1:nspec-1 will produce a size nspec vector starting at 0.

1:(nspec-1) starts at 1, and is of size nspec-1

Upvotes: 1

Related Questions