简体   繁体   中英

How can I avoid spaces when collapsing a character vector?

I have a character vector and want an output like this:

"(WLNXL0427M)|(QWDAF7505E)|(ZTKQC4319H)|(RUQAI0874B)|(BAUPR0486O)"

I use

v <- c("WLNXL0427M", "QWDAF7505E", "ZTKQC4319H", "RUQAI0874B", "BAUPR0486O")
a <- paste("(", v, collapse = "|", ")")
a

And get

"( WLNXL0427M )|( QWDAF7505E )|( ZTKQC4319H )|( RUQAI0874B )|( BAUPR0486O )"

How can I avoid the spaces?

Also paste0() could be used ie

v <- c("WLNXL0427M", "QWDAF7505E", "ZTKQC4319H", "RUQAI0874B", "BAUPR0486O")
a <- paste0("(", v, collapse = "|", ")")
a

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM