[R] Odp: Cutting a vector

jim holtman jholtman at gmail.com
Thu Nov 22 15:56:00 CET 2007


If you want to 'cut' the vector into equal lengths of 4, for example,
then the following would work:

split(x, as.integer((seq_along(x) - 1) / 4))


On Nov 22, 2007 9:44 AM, Dani Valverde <daniel.valverde at uab.cat> wrote:
> Hello,
> That's very useful. I think the cut() function is the key. However, in
> my real vector I have 13112 points. I would like the function to cut the
> vector every certain number of points (ie 4). Is there a way to specify
> this without the need of writing each cutting point? For example, I do
> not want to write breaks=c(4,8,12,...,13108, +Inf), but some expresion
> to avoid writing such a long argument.
> Best regards,
>
> Dani
>
> En/na Petr PIKAL ha escrit:
> > 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 guide
> >>
> > http://www.R-project.org/posting-guide.html
> >
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> >
> >
>
>
> --
> 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?



More information about the R-help mailing list