[英]Add line breaks to a long string in R - Tidyverse soultion?
I have a long string and want to add line breaks in a systematic way.我有一个很长的字符串,想以系统的方式添加换行符。 I want to add the line break after Yrkeshögskoleutbildning 2018. Regardless of what comes after.
我想在 Yrkeshögskoleutbildning 2018 之后添加换行符。不管之后是什么。 Is there perhaps an elegant
tidyverse
solution?也许有一个优雅的
tidyverse
解决方案?
string <- "2120002122;Arboga Kommun ;Arboga kommun, Vuxenutbildningen;Specialistundersköterska inom demens;415723rb;1984;Arboga Kommun;Yrkeshögskoleutbildning 20182120001561;Borås Kommun;Borås Stad - Borås Yrkeshögskola;Automationsingenjör;525523fa;1490;Haglund Industri AB;Yrkeshögskoleutbildning 20181"
You can use str_split
and positive lookbehind:您可以使用
str_split
和正向后视:
library(stringr)
str_split(string, "(?<=Yrkeshögskoleutbildning 2018)")
[[1]]
[1] "2120002122;Arboga Kommun ;Arboga kommun, Vuxenutbildningen;Specialistundersköterska inom demens;415723rb;1984;Arboga Kommun;Yrkeshögskoleutbildning 2018"
[2] "2120001561;Borås Kommun;Borås Stad - Borås Yrkeshögskola;Automationsingenjör;525523fa;1490;Haglund Industri AB;Yrkeshögskoleutbildning 2018"
[3] "1"
Use unlist
to get a vector:使用
unlist
获取向量:
unlist(str_split(string, "(?<=Yrkeshögskoleutbildning 2018)"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.