Witold,
Here's one way:
Vec <- rnorm(30)
Vec.cut <- cut(Vec, breaks=c(quantile(Vec, probs = seq(0, 1, by = 0.20))),
labels=c("0-20","20-40","40-60","60-80","80-100"),
include.lowest=TRUE)
table(Vec.cut)
or determine the breaks automatically:
cut.size <- function(x, size) {
cut.prob <
Here's one way:
Vec <- rnorm(30)
Vec.cut <- cut(Vec, breaks=c(quantile(Vec, probs = seq(0, 1, by = 0.20))),
labels=c("0-20","20-40","40-60","60-80","80-100"), include.lowest=TRUE)
table(Vec.cut)
or determine the breaks automatically:
cut.size <- function(x, size) {
cut.prob <- size/leng
Greg,
Good catch. My recollection was that the vector would be broken up into
'breaks' groups of equal size, however it is range(x) that is split into
'breaks' intervals, each of which is equal width.
Thanks,
Marc
On Jul 18, 2013, at 10:55 AM, Greg Snow <538...@gmail.com> wrote:
> Marc,
>
my fault. qcut() is a python function in pandas ;-)
what i meant is cut2() in hmisc.
sorry for messing up.
On Jul 18, 2013 11:51 AM, "Greg Snow" <538...@gmail.com> wrote:
> Wensui,
>
> ?qcut on my machine gives an error and ??qcut does not find anything in
> the installed packages. Which packa
Marc,
Your method works fine when the data is perfectly uniform, but try it with
"Vec <- rnorm(30)" and you will see that there are more observations in the
middle groups and fewer in the tail groups. Something like quantile needs
to be used to find the unequally spaced breaks that will give equa
Wensui,
?qcut on my machine gives an error and ??qcut does not find anything in
the installed packages. Which package is qcut in?
On Wed, Jul 17, 2013 at 4:43 PM, Wensui Liu wrote:
> ?qcut
> On Jul 17, 2013 5:45 PM, "Witold E Wolski" wrote:
>
> > I would like to "cut" a vector into groups o
On Jul 17, 2013, at 4:43 PM, Witold E Wolski wrote:
> I would like to "cut" a vector into groups of equal nr of elements.
> looking for a function on the lines of cut but where I can specify
> the size of the groups instead of the nr of groups.
In addition to the other options, if the 'breaks'
?qcut
On Jul 17, 2013 5:45 PM, "Witold E Wolski" wrote:
> I would like to "cut" a vector into groups of equal nr of elements.
> looking for a function on the lines of cut but where I can specify
> the size of the groups instead of the nr of groups.
>
>
>
>
> --
> Witold Eryk Wolski
>
> __
:04 PM
Subject: Re: [R] cut into groups of equal nr of elements...
HI,
Not sure whether this is what you wanted.
vec1<- 1:7
fun1<- function(x,nr) {((x-1)%/%nr)+1}
fun1(vec1,2)
#[1] 1 1 2 2 3 3 4
fun1(vec1,3)
#[1] 1 1 1 2 2 2 3
split(vec1,fun1(vec1,2))
A.K.
- Original Messag
HI,
Not sure whether this is what you wanted.
vec1<- 1:7
fun1<- function(x,nr) {((x-1)%/%nr)+1}
fun1(vec1,2)
#[1] 1 1 2 2 3 3 4
fun1(vec1,3)
#[1] 1 1 1 2 2 2 3
split(vec1,fun1(vec1,2))
A.K.
- Original Message -
From: Witold E Wolski
To: r-help@r-project.org
Cc:
Sent: Wednesday,
You could use the quantile function to choose the cut points and pass that
to cut.
Or you could sort the vector and just take the first n elements as the 1st
group, etc.
On Wed, Jul 17, 2013 at 3:43 PM, Witold E Wolski wrote:
> I would like to "cut" a vector into groups of equal nr of elements
11 matches
Mail list logo