示例数据:
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
&amp; read.lines
sep=","
{{1}}没有成功。
答案 0 :(得分:5)
你在审美之后不是这个答案的功能:
cat(paste0('"', paste(char, collapse="\", \""), '"'))
## "115030", "118990", "72910", "121050", "93820", "119310", "110370", "100590", "98220", "118200"
存储:
store <- paste0('"', paste(char, collapse="\", \""), '"')
答案 1 :(得分:0)
sink
函数可用于强制输出文本。
sink('output.txt')
cat(paste0('"', paste(char, collapse="\", \""), '"'))
sink()