[R] split element vector

Bill Dunlap w||||@mwdun|@p @end|ng |rom gm@||@com
Fri Aug 6 16:17:45 CEST 2021


unlist(strsplit(vect, "\n"))

On Fri, Aug 6, 2021 at 7:13 AM Luigi Marongiu <marongiu.luigi using gmail.com>
wrote:

> Hello,
> I have a vector that contains some elements with concatenated values, such
> as:
> ```
> > vect
> [1] "name_1"
> [2] "name_2"
> [3] "name_3\nsurname_3"
> [4] "some other text\netc"
> ```
> How can I create a new vector where each component is an element, such as:
> ```
> > vect
> [1] "name_1"
> [2] "name_2"
> [3] "name_3"
> [4] "surname_3"
> [5] "some other text"
> [6] "etc"
> ```
> I can split the elements on '\n' but how do I transfer these directly
> on a new vector?
> Thanks
>
> ______________________________________________
> R-help using 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]]



More information about the R-help mailing list