[R] create index for tapply or by
Gerrit Eichner
Gerrit.Eichner at math.uni-giessen.de
Thu Jun 27 10:43:57 CEST 2013
Hi, Witold,
take a look at
?findIntervals
It might give want you need.
Hth -- Gerrit
On Thu, 27 Jun 2013, Witold E Wolski wrote:
> Is there a build in function to create an index for tapply or by given a
> a numeric vector x an a vector of breaks?
>
> What I want to do is:
>
> x <- 1:100
> breaks <- c(0,10,20,50,99,110)
>
> y <- rep(0,length(x))
> for(i in 2:length(breaks)){
> y[which(x>breaks[i-1] & x <= breaks[i])] <- i
> }
>
> by(x,y,sum)
>
> but I find the code especially th for loop unneRving.
>
>
> --
> Witold Eryk Wolski
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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