【发布时间】:2015-10-18 09:31:11
【问题描述】:
我有一个非常大的矩阵,想保存到本地以备后用。这是我的矩阵:
head(copy_fourgram)
[,1] [,2] [,3] [,4] [,5]
[1,] "\u0097" "a" "moment" "when" "1"
[2,] "\u0096" "and" "of" "support" "1"
[3,] "\u0095" "eli" "lathrop" "yard" "1"
[4,] "\u0095" "james" "brown" "yard" "1"
[5,] "\u0095" "keep" "a" "fire" "1"
[6,] "\u0097" "maybe" "even" "vent" "1"
这是我要保存的代码:
library(MASS)
write.matrix(format(copy_fourgram, scientific=FALSE),
file = paste("./en_US/ngrams/", "copy_fourgram.csv", sep="/"), sep=",")
当我以 csv 格式回读时:
fourgram_file <- file("./en_US/ngrams/fourgram.csv", "r")
new_copy_fourgram <- read.csv(fourgram_file, header=T)
close(fourgram_file)
new_copy_fourgram <- as.matrix(new_copy_fourgram)
head(new_copy_fourgram)
X. a moment X1 when
[1,] "\u0096 " "and " "of "1" " "support "
[2,] "\u0095 " "eli " "lathrop "1" " "yard "
[3,] "\u0095 " "james " "brown "1" " "yard "
[4,] "\u0095 " "keep " "a "1" " "fire "
[5,] "\u0097 " "maybe " "even "1" " "vent "
[6,] "½ " "years " "old "1" " "now "
如您所见,我在这里有多个格式问题,包括标题和引号放错了位置。关于如何通过该过程保留此矩阵的任何见解?谢谢!
【问题讨论】: