我有一个字符向量,想要一个像这样的输出:
"(WLNXL0427M)|(QWDAF7505E)|(ZTKQC4319H)|(RUQAI0874B)|(BAUPR0486O)"
我用
v <- c("WLNXL0427M", "QWDAF7505E", "ZTKQC4319H", "RUQAI0874B", "BAUPR0486O")
a <- paste("(", v, collapse = "|", ")")
a
得到
"( WLNXL0427M )|( QWDAF7505E )|( ZTKQC4319H )|( RUQAI0874B )|( BAUPR0486O )"
如何避免空格?
答案 0 :(得分:3)
也可以使用paste0()
,即
v <- c("WLNXL0427M", "QWDAF7505E", "ZTKQC4319H", "RUQAI0874B", "BAUPR0486O")
a <- paste0("(", v, collapse = "|", ")")
a