[R] Creating vegetation distance groups from one column

Rui Barradas ruipbarradas at sapo.pt
Thu Oct 4 14:27:40 CEST 2012


Hello,

Without sample data it's difficult to give an answer but see ?cut.
To give a data example, the best way is to use ?dput().

dput( head(mydata, 30) )  # Paste the output of this in a post

Hope this helps,

Rui Barradas
Em 04-10-2012 08:27, Jhope escreveu:
> Hi R listers,
>
> I am trying to group distances of nests to the vegetation into classes that
> are define by (0-5m, 6-10m, 11-15m, 16-20m, 21-25m, 26-30m, 31-35m,  36-40m,
> 41-45m, 46-50m, 51-55m, 56-60m). Each row is a nest and all the distances to
> the vegetation is in a column.
>
> In plyr, I have tried - below script but I think I am going about this the
> wrong way and am not successful.
>
> #Veg index star = resp
> Veg.index <- function(values, weights=c(0, 5, 10, 15, 20, 25, 30, 35, 40,
> 45, 50, 55, 60, 65, 70)) {
>    star <- values*weights
>    return(apply(star, 1, sum) / apply(values, 1, sum))
> }
> data.to.analyze$VegIndex <- Veg.index(data.to.analyze[,c("0", "5", "10",
> "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70")])
> write.csv(data.to.analyze, "3turtlehatch.csv", row.names=FALSE)
>
> Please advise, Jean
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Creating-vegetation-distance-groups-from-one-column-tp4644970.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