Jean,

Take a look at the cut() function,
?cut

For example ...

mydf <- data.frame(nest=1:100, d2veg=runif(100, 0, 60))
mydf$dgroup <- cut(mydf$d2veg, breaks=seq(0, 70, 5), include.lowest=TRUE)
head(mydf)

(another) Jean



Jhope <jeanwaij...@gmail.com> wrote on 10/04/2012 02:27:38 AM:
> 
> 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

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to