Skip to content
Back to formatted view

Raw Message

Message-ID: <512D13F6.4040708@sapo.pt>
Date: 2013-02-26T19:58:46Z
From: Rui Barradas
Subject: cut a vector in equal parts
In-Reply-To: <471326D5-69EB-4276-B863-CD257F44213B@googlemail.com>

Hello,

Try the following.

x <- rnorm(500)^2
split(x, cut(x, quantile(x, probs = seq(0, 1, by = 0.2))))


Hope this helps,

Rui Barradas

Em 26-02-2013 17:39, Martin Batholdy escreveu:
> Hi,
>
> I would like to cut a vector of values in parts.
> Each part should have an equal number of elements.
>
> for example:
>
> x <- (rnorm(500)^2)
>
> now I want 5 vectors each with 100 elements.
> The first vector should include the 100 lowest values of x and so on
> (so that the fifth vector contains the 100 highest values of x).
>
>
> thanks for any help!
>
> ______________________________________________
> 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.
>