gpt4 book ai didi

r - 用 R 在字符之间插入逗号

转载 作者:行者123 更新时间:2023-12-03 22:48:17 27 4
gpt4 key购买 nike

样本数据:

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.linessep=","没有成功。

最佳答案

你追求的是审美而不是这个答案的功能:

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com