1

我正在尝试将列表作为一行写入文件,并且在 R 中不带引号。

清单内容为:

 [1] "X4775495036_J" "X4775495036_F" "X5147722015_F" "X5067554009_F"
 [5] "X5067554063_B" "X4954590047_A" "X5067554063_G" "X5067554009_L"
 [9] "X5147722015_D" "X5511045011_D" "X5067554063_A" "X4805447025_F"
[13] "X5455362015_K" "X4805447025_L" "X5147722015_B" "X5067554009_G"
[17] "X5147722014_K" "X5067554063_H" "X5147722009_G" "X5067554008_H"
[21] "X5067554054_H" "X4805447016_K" "X5147722014_E" "X4954590051_K"
[25] "X5067554008_E" "X5147722015_H" "X5147722009_H" "X5067554063_D"
[29] "X5147722015_A" "X5511045022_E" "X5067554054_I" "X5067554063_J"
[33] "X5067554007_F" "X4775495036_E" "X4775495036_H" "X4805447025_H"
[37] "X5067554009_I" "X4805447025_K" "X4954590051_C" "X4805447025_E"
[41] "X5067554063_E" "X5147722009_J" "X5067554054_C" "X5067554054_G"
[45] "X4805447016_I" "X5455362015_B" "X5067554009_H" "X5147722014_A"
[49] "X4775495036_I" "X5067554063_L" "X5455362015_J" "X4954590047_J"
[53] "X5067554009_A" "X4954590051_D" "X5455362015_I" "X5511045011_E"
[57] "X5147722014_F"

我想要这样的东西(一行中的所有元素):

X4775495036_J X4775495036_F X5147722015_F X5067554009_F ...

我试过了write.tablewrite但没有结果。

4

2 回答 2

4

请注意,您没有列表,您有一个字符向量。

cat(your_vector, "\n", file="your_file.txt")

最后"\n"是可选的换行符。

于 2013-06-30T10:59:58.423 回答
2

您可以使用ncolumnswrite 的参数:

n <- LETTERS[1:10] # create example values
write(n, "letters.txt", ncolumns=length(n))

或者你可以在之前连接你的名字:

nc <- paste0(n, collapse=" ")
write(nc, "letters.txt")
于 2013-06-30T10:55:06.067 回答