[R] cut data into sevral group and assign calculated values individually

Uwe Ligges ligges at statistik.tu-dortmund.de
Tue Oct 18 11:22:55 CEST 2011



On 17.10.2011 20:53, Li, Yan wrote:
> Hi All,
>
> I have some data from which I set four points to be breaks. Based on these points,  I cut the dataset into four groups and assign a number to it:
>
> <=331.04 assign 0
>> 331.04<=476.07 assign data-331.04/(476.07-331.04)
>> 476.07<=608.66  assign 1
>> 608.66<=791.5 assign 791.5- data/(791.5-608.66)
>> 791.5 and NA assign 0
>
>
> Breaks                  331.04      476.07      608.66       791.5                    NA
> m_group        0                 x                 1                 x               0                    0
>
>
> I can use cut() to group the data according to the breaks but having difficulty to assign the two calculated interval values.
>


Based on the levels of the factor resulted by cut(), you can calculate a 
new vector easily. But since you have not specified a reproducible 
example, I cannot quickly change it in order to show how it works.

Best,
Uwe Ligges



> Thank you very much!
>
> Regards,
> Yan
>
> 	[[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