[R] Add "bin" variable to dataframe

Henrique Dallazuanna wwwhsd at gmail.com
Tue Nov 17 16:59:22 CET 2009


Try this:

cut(x, breaks = breaks, labels = sprintf("bin%d", 1:10))

On Tue, Nov 17, 2009 at 1:43 PM, Gunadi <boydkramer at gmail.com> wrote:
>
> Hi All - I am trying to add a new variable to my dataframe which is a series
> of bins based on another variable which is distance. So, I'd like to end
> with each of my distances classified into bin 1, bin 2, bin 3 etc.
>
> Below is a start.
>
> x<-rnorm(100, mean=100, sd=30) #Generates sample distances
> breaks = seq(0, 200, l = 11) #Generates 10 bins of equal distance (i.e.
> 20km)
>
> Any ideas?
>
> Best,
>
> Gunadi
> --
> View this message in context: http://old.nabble.com/Add-%22bin%22-variable-to-dataframe-tp26392102p26392102.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O




More information about the R-help mailing list