Hello everyone, I have a data set, and I need to bin my data using a bin width of say g(n). Would anyone be willing to tell me how to do this in R? Thanks -- View this message in context: http://r.789695.n4.nabble.com/Simple-question-on-binning-data-tp2202644p2202644.html Sent from the R help mailing list archive at Nabble.com.
There would be several people who could help if you gave us a minimal, reproducible example like the posting guide asks for. If you have a vector of continuous data, and need to create a categorical variable (in R, a factor) from that continuous variable, then ?cut can help you. george5000 wrote:> Hello everyone, > > I have a data set, and I need to bin my data using a bin width of say g(n). > Would anyone be willing to tell me how to do this in R? > > Thanks
It's very simple to write a "binit()" function. If all you want to do is e.g., bin 107 values into sums of 10 at a time, then write a loop that sums x[10*i:11*i-1] (not tested and not syntactically correct). The one I wrote for myself discards any partial bin (101-107 in my example) and leaves a warning note that this took place. Carl