Hello, I have a vector, lets say x <- 1:50 I would like it to be cut at certain points, being for example 1:5, 6:11, 12:17, ... How can I do it? I have tried the cut() function, but I don not know how to place the cutting points properly. Best regards, Dani -- Daniel Valverde Saub? Grup de Biologia Molecular de Llevats Facultat de Veterin?ria de la Universitat Aut?noma de Barcelona Edifici V, Campus UAB 08193 Cerdanyola del Vall?s- SPAIN Centro de Investigaci?n Biom?dica en Red en Bioingenier?a, Biomateriales y Nanomedicina (CIBER-BBN) Grup d'Aplicacions Biom?diques de la RMN Facultat de Bioci?ncies Universitat Aut?noma de Barcelona Edifici Cs, Campus UAB 08193 Cerdanyola del Vall?s- SPAIN +34 93 5814126
Hi you shall be more specific. Do you want to split your vector according some pionts split(x, findInterval(x, c(6,12,16))) if you want to make a factor from your x vector, then you can use findInterval or cut cut(x, breaks = c(0,6,12,17, +Inf)) Or something else? Regards Petr petr.pikal at precheza.cz r-help-bounces at r-project.org napsal dne 22.11.2007 12:52:38:> Hello, > I have a vector, lets say > x <- 1:50 > I would like it to be cut at certain points, being for example 1:5, > 6:11, 12:17, ... > How can I do it? I have tried the cut() function, but I don not know how> to place the cutting points properly. > Best regards, > > Dani > > -- > Daniel Valverde Saub? > > Grup de Biologia Molecular de Llevats > Facultat de Veterin?ria de la Universitat Aut?noma de Barcelona > Edifici V, Campus UAB > 08193 Cerdanyola del Vall?s- SPAIN > > Centro de Investigaci?n Biom?dica en Red > en Bioingenier?a, Biomateriales y > Nanomedicina (CIBER-BBN) > > Grup d'Aplicacions Biom?diques de la RMN > Facultat de Bioci?ncies > Universitat Aut?noma de Barcelona > Edifici Cs, Campus UAB > 08193 Cerdanyola del Vall?s- SPAIN > +34 93 5814126 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Here is another way of doing it:> x <- 1:50 > split(x, as.integer(seq(0, by=1, length=length(x))/5))$`0` [1] 1 2 3 4 5 $`1` [1] 6 7 8 9 10 $`2` [1] 11 12 13 14 15 $`3` [1] 16 17 18 19 20 $`4` [1] 21 22 23 24 25 $`5` [1] 26 27 28 29 30 $`6` [1] 31 32 33 34 35 $`7` [1] 36 37 38 39 40 $`8` [1] 41 42 43 44 45 $`9` [1] 46 47 48 49 50>On Nov 22, 2007 6:52 AM, Dani Valverde <daniel.valverde at uab.cat> wrote:> Hello, > I have a vector, lets say > x <- 1:50 > I would like it to be cut at certain points, being for example 1:5, > 6:11, 12:17, ... > How can I do it? I have tried the cut() function, but I don not know how > to place the cutting points properly. > Best regards, > > Dani > > -- > Daniel Valverde Saub? > > Grup de Biologia Molecular de Llevats > Facultat de Veterin?ria de la Universitat Aut?noma de Barcelona > Edifici V, Campus UAB > 08193 Cerdanyola del Vall?s- SPAIN > > Centro de Investigaci?n Biom?dica en Red > en Bioingenier?a, Biomateriales y > Nanomedicina (CIBER-BBN) > > Grup d'Aplicacions Biom?diques de la RMN > Facultat de Bioci?ncies > Universitat Aut?noma de Barcelona > Edifici Cs, Campus UAB > 08193 Cerdanyola del Vall?s- SPAIN > +34 93 5814126 > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?