Re: [R] Binning the data based on a value

2011-12-05 Thread R. Michael Weylandt
Add the drop = TRUE command to split ?split split(a, cut(a$spending, breaks = (0:5)*100), drop = TRUE) Michael On Mon, Dec 5, 2011 at 4:06 PM, Diviya Smith wrote: > Thank you very much Michael. This is very helpful. However, if there is any > way to exclude zero length bins. Lets imagine that t

Re: [R] Binning the data based on a value

2011-12-05 Thread Diviya Smith
Thank you very much Michael. This is very helpful. However, if there is any way to exclude zero length bins. Lets imagine that the matrix was as follows - a <- data.frame(patient=1:7, charges=c(100,500,200,90,400,500,600), age=c(0,3,5,7,10,16,19), spending=c(10, 60, 110, 200, 400, 450, 500)) bi

Re: [R] Binning the data based on a value

2011-12-05 Thread R. Michael Weylandt
Just a clarification: I can't get round to work as I first expected so if you want to do bins by 100's you'd probably want: split(a, cut(a$spending, breaks = (0:5)*100)) Michael On Mon, Dec 5, 2011 at 3:41 PM, R. Michael Weylandt wrote: > I'd so something like > > split(a, a$spending) > > and y

Re: [R] Binning the data based on a value

2011-12-05 Thread R. Michael Weylandt
I'd so something like split(a, a$spending) and you can include a round(a$spending, -2) or something similar if you want to group by the 100's. Michael On Mon, Dec 5, 2011 at 3:37 PM, Diviya Smith wrote: > Hello there, > > I have a matrix with some data and I want to split this matrix based on

[R] Binning the data based on a value

2011-12-05 Thread Diviya Smith
Hello there, I have a matrix with some data and I want to split this matrix based on the values in one column. Is there a quick way of doing this? I have looked at cut but I am not sure how to exactly use it? for example: I would like to split the matrix "a" based on the spending such that the da