是否有任何简单的方法,当在 R 中使用 sink() 写入 csv 文件时,写入前 2 个单元格为空白且第三个单元格具有特定字符串的行?这并不是那么简单,我正在为此苦苦挣扎。我尝试了以下方法:
# this approach writes all 5 numbers in one (the first) line with 2 spaces between each number
sink('myfile.csv')
for(i in 1:5) {
cat(c(' ', ' ', i))
}
sink()
# this approach writes each number on its own line, but in the 1st column with 2 spaces the number
sink('myfile.csv')
for(i in 1:5) {
cat(c(' ', ' ', i), '\n')
}
sink()
# this approach throws an error
sink('myfile.csv')
for(i in 1:5) {
a = data.frame(` ` = '', ` ` = '', `Requested Access?` = '')
cat(a, '\n')
}
sink()
为了验证,我在上面的示例中所需的输出将是一个 CSV 文件,其中每个数字 1、2、3、4、5 在它们自己的行中,每个在 C 列中。对此的任何帮助表示赞赏!