我们可以gsub
用来删除空白区域.我们选择一个或多个空格(\\s+
)并替换为''
.
df$names <- gsub('\\s+', '', df$names) df$names #[1] "stock1" "stockstock12" "stock2"
然后,我们使用paste
将字符串连接在一起
path <- "C:/Desktop/stock_files" df$names <- paste(path, df$names, sep="/") df$names #[1] "C:/Desktop/stock_files/stock1" "C:/Desktop/stock_files/stockstock12" #[3] "C:/Desktop/stock_files/stock2"