[R] cut into groups of equal nr of elements...
arun
smartpink111 at yahoo.com
Thu Jul 18 00:37:38 CEST 2013
Sorry, there was a mistake:
fun1 should be:
fun1<- function(x,nr) {((seq_along(x)-1)%/%nr)+1}
vec3<- c(4,5,7,9,8,5)
fun1(vec3,2)
#[1] 1 1 2 2 3 3
split(vec3,fun1(vec3,2))
A.K.
----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: Witold E Wolski <wewolski at gmail.com>
Cc: R help <r-help at r-project.org>
Sent: Wednesday, July 17, 2013 6: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 Message -----
From: Witold E Wolski <wewolski at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Wednesday, July 17, 2013 5:43 PM
Subject: [R] cut into groups of equal nr of elements...
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
______________________________________________
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