样本数据:
data <- round(rnorm(10,100000,10000),-1)
char <- as.character(data)
我想在字符之间使用逗号:
[1] "104350","108800","101320","94140","102260","89340","114220","105830","111270","85300"
我试过
paste()
还有 read.table
& read.lines
与 sep=","
没有成功。
最佳答案
你追求的是审美而不是这个答案的功能:
cat(paste0('"', paste(char, collapse="\", \""), '"'))
## "115030", "118990", "72910", "121050", "93820", "119310", "110370", "100590", "98220", "118200"
储藏:
store <- paste0('"', paste(char, collapse="\", \""), '"')
关于r - 用 R 在字符之间插入逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23585306/