[R] Creating vegetation distance groups from one column

Rui Barradas ruipbarradas at sapo.pt
Sat Oct 6 11:55:03 CEST 2012


Hello,

My example with 'x' was just that, an example. Inline.

Em 06-10-2012 00:03, Jhope escreveu:
> Hi,
>
> I have tried the script posted but received the following errors.  I hope I
> copied it correctly. I'm sorry but I don't know how to alter the script
> myself.
> Please advise, Jean
>
>> x <- 0:30 + runif(124)
>> data.to.analyze$VegIndex <- cut(x, breaks = seq(0, 35, 5))
> Error in `$<-.data.frame`(`*tmp*`, "VegIndex", value = c(1L, 1L, 1L, 1L,  :
>    replacement has 124 rows, data has 123

Use

cut(data.to.analize$VegIndex, breaks = seq(0, 35, 5))

>> l <- levels(data.to.analyze$VegIndex)
>> l1 <- sub("\\]", ")", l[1])
>> l2 <- as.numeric(sub("\\(([[:digit:]]+),.*", "\\1", l[-1])) + 1
>> l3 <- sub(".*,([[:digit:]]+).*", "\\1", l[-1])
>> l.new <- c(l1, paste0("(",l2,",",l3, ")"))
> Error: could not find function "paste0"

paste0 was introduced with R 2.15.0, update your version of R and in the 
mean time use

paste(...etc..., sep = "")


Rui Barradas
>> levels(data.to.analyze$VegIndex) <- l.new
> Error: object 'l.new' not found
>> str(data.to.analyze$VegIndex)
>   NULL
>> barplot(table(data.to.analyze$VegIndex))
> Error in plot.window(xlim, ylim, log = log, ...) :
>    need finite 'xlim' values
> In addition: Warning messages:
> 1: In min(w.l) : no non-missing arguments to min; returning Inf
> 2: In max(w.r) : no non-missing arguments to max; returning -Inf
> 3: In min(x) : no non-missing arguments to min; returning Inf
> 4: In max(x) : no non-missing arguments to max; returning -Inf
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Creating-vegetation-distance-groups-from-one-column-tp4644970p4645230.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list