# [R] Continuous variable into levels

Neha gupta neh@@bo|ogn@90 @end|ng |rom gm@||@com
Fri Mar 4 10:26:03 CET 2022

```Thank you dear Rui

Yes, it helps.

Best regards

> Hello,
>
> And ?findInterval is faster than hist.
>
> findInterval(x, c(-Inf, 500, 1000, 5000))
>
> Also, before the cut code, the OP wrote
>
>
> if value is between 1-100 do something
>
>
> but in the breaks vector there's no 100. I guess this is not important,
> though, only the function to bin the data is.
>
> Hope this helps,
>
>
> Às 22:38 de 03/03/2022, Jim Lemon escreveu:
>
>> Sorry, it was such an easy question that I didn't even read it
>> closely. Apparently using hist() is a bit faster. Whether this is
>> worth it, I don't know.
>>
>> Jim
>>
>> On Fri, Mar 4, 2022 at 9:36 AM Neha gupta <neha.bologna90 using gmail.com>
>> wrote:
>>
>>>
>>> Hello Jim
>>>
>>> So, you believe the following way is better ?
>>>
>>> var2=cut(var1, br=c(-1,500, 501,1000, 1001,5000))
>>>
>>>
>>>
>>> On Thu, Mar 3, 2022 at 11:29 PM Jim Lemon <drjimlemon using gmail.com> wrote:
>>>
>>>>
>>>> Hi Neha,
>>>> I think you're looking for the "cut" function.
>>>>
>>>> Jim
>>>>
>>>> On Fri, Mar 4, 2022 at 8:10 AM Neha gupta <neha.bologna90 using gmail.com>
>>>> wrote:
>>>>
>>>>>
>>>>> Hello everyone
>>>>>
>>>>> I have a variable with about 5000 different values
>>>>>
>>>>> var1= c(0, 123, 400, .....4988)
>>>>>
>>>>> I want to convert it into different levels for some comparisons like
>>>>>
>>>>> if value is between 1-100 do something
>>>>> else
>>>>> do other things
>>>>>
>>>>> Is there any sophisticated way to do that than the following:
>>>>>
>>>>> var2=cut(var1, br=c(-1,500, 501,1000, 1001,5000))
>>>>>
>>>>> Thank you
>>>>>
>>>>>          [[alternative HTML version deleted]]
>>>>>
>>>>> ______________________________________________
>>>>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>>> ng-guide.html
>>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>>
>>>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help