Error: argument of length 0 returned in R -


background:

i working functional diversity index fris who's r script provided @ : http://www.irstea.fr/la-recherche/unites-de-recherche/hyax/ecology-schleuter-2010

i have had number of problems script running errors think have found solutions to, novice in r , cannot fix latest one.

it involves use of 3 data.frames number of each species of animal @ each habitat type, , max , min values of trait each species such as:

abundance1

location s1 s2 s3 s4 s5 s6 s7 s8 s9 palm      6  3  0  1  0 16  0  2  3 forest    2  0  2  1  2  1  3  0  2 

max1

 species     max    s1        44.7344    s2        22.6966    s3        75.1817    s4        17.8176    s5        50.7472     s6        33.3660    s7        14.3341    s8        3.3947    s9        10.2510 

min1

 species     min    s1        25.3038    s2        19.5750    s3        60.5880    s4        16.2864    s5        46.1040    s6        10.9056    s7        8.7570    s8        2.1289    s9        4.1730 

what i've done:

the script starts think extracting min, max , abundance data , ordering them species.

abundance1 <- read.table("put here path/sites.txt",h=t) rownames(abundance1) <- abundance1[,1] abundance <- abundance1[,-1] abundance <- abundance[,order(colnames(abundance))]  min1 <- read.table("put here path/min_traits.txt",h=t) max1 <- read.table("put here path/max_traits.txt",h=t)  rownames(min1) <- min1[,1] minsp <- min1[,-1] minsp <- minsp[order(rownames(minsp)),]  rownames(max1) <- max1[,1] maxsp <- max1[,-1] maxsp <- maxsp[order(rownames(maxsp)),]  

initially final line of maxsp sending error saying argument (rownames(maxsp)) not vector, final line of minsp. realised might have been because rownames() function changed part of code rownamesm max , rownamesm minimum.

after sent errors saying maxsp[order(rownamesm,] had wrong number of dimensions, , again same minsp. thought might have been because extract function reducing dimensions down added drop = false each of extractions left me code seems work:

rownamesa <- abundance1[,1, drop=false] abundance <- abundance1[,-1, drop=false] abundance <- abundance[order(colnames(abundance))]  rownamesm <- min1[,1, drop=false] minsp <- min1[,-1, drop= false] minsp <- minsp[order(rownamesm),]  rownamesm <- max1[,1, drop=false] maxsp <- max1[,-1, drop=false] maxsp <- maxsp[order(rownamesm),] 

however have messed when run next part of script error says error in 1:ncol(minsp) : argument of length 0

here next part of script:

globalfri <- function(minsp,maxsp) {   deltas <- list()    (j in 1:ncol(minsp))   {     xx <- cbind(minsp[,j], maxsp[,j])     xx <- xx[apply(xx,1,function(z) sum(is.finite(z))==2),]     xx <- xx[order(xx[,1]),]     z <- c(0, nrow(xx))     <- 1     b <- xx[1, 2]     while ( < nrow(xx) )     {       if (b < xx[i+1,1]) z <- c(z, i)       b <- ifelse(b >= xx[i+1,2], b, xx[i+1,2])       <- i+1       if (i==nrow(xx)) break     }     group <- factor(rep(1:(length(z)-1), diff(sort(z))))     deltas[[j]] <- tapply(xx[,2], group, max) - tapply(xx[,1], group, min)   }    globalfris <- sapply(deltas, sum)}  globalfriall <- globalfri(minsp,maxsp) 

i @ complete loss , don't know next. please give me pointers have gone wrong?

thanks in advance

you forgot drop = false:

iris <- iris[, 1, drop = false] iris[order(iris[,1]),] #a vector; ncol return null iris[order(iris[,1]), , drop = false] #a data.frame 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -