Message-ID: <CAF8bMcaA-i9=atbRQjj=tVh+u77adzKfHo+fQFCCmNkG1akTZg@mail.gmail.com>
Date: 2016-12-09T00:05:41Z
From: William Dunlap
Subject: creating possible cominations of a vector's elements
In-Reply-To: <CAN2xGJbbtgkXCQr8WGLMAphSzX2JmKWg6xH5QQXH2K5=6M9pUA@mail.gmail.com>
> ij <- combn(length(x)+1, 2)
> lapply(seq_len(ncol(ij)), function(k) x[ij[1,k]:(ij[2,k]-1)])
[[1]]
[1] "this"
[[2]]
[1] "this" "is"
...
[[9]]
[1] "my" "vector"
[[10]]
[1] "vector"
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Thu, Dec 8, 2016 at 3:02 PM, Dimitri Liakhovitski <
dimitri.liakhovitski at gmail.com> wrote:
> Hello!
>
> I have a vector of strings 'x' that was based on a longer string
> 'mystring' (the actual length of x is unknown).
>
> mystring <- "this is my vector"
> x <- strsplit(mystr, " ")[[1]]
>
> I am looking for an elegant way of creating an object (e.g., a list)
> that contains the following strings:
>
> "this"
> "this is"
> "this is my"
> "this is my vector"
> "is"
> "is my"
> "is my vector"
> "my"
> "my vector"
> "vector"
>
> Thanks a lot!
>
> --
> Dimitri
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
[[alternative HTML version deleted]]