【发布时间】:2015-11-11 11:23:58
【问题描述】:
我正在使用ca 包进行对应分析。我已使用author 数据进行分析,效果非常好。
library(ca)
head(author[,1:5])
a b c d e
three daughters (buck) 550 116 147 374 1015
drifters (michener) 515 109 172 311 827
lost world (clark) 590 112 181 265 940
east wind (buck) 557 129 128 343 996
farewell to arms (hemingway) 589 72 129 339 866
sound and fury 7 (faulkner) 541 109 136 228 763
str(author)
num [1:12, 1:26] 550 515 590 557 589 541 517 592 576 557 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:12] "three daughters (buck)" "drifters (michener)" "lost world (clark)" "east wind (buck)" ...
..$ : chr [1:26] "a" "b" "c" "d" ...
ca(author[,1:5])
Principal inertias (eigenvalues):
1 2 3 4
Value 0.008122 0.001307 0.001072 0.000596
Percentage 73.19% 11.78% 9.66% 5.37%
...
然后我尝试将author 数据写入 csv 并读取 csv 以再次执行分析。然后ca 不起作用。读取的 csv 文件的str 不同,不像列联表。因此,ca 函数会产生错误。
author1 <- read.csv("author.csv")
colnames(author1)[1] <- ""
head(author1[,1:5])
a b c d
1 three daughters (buck) 550 116 147 374
2 drifters (michener) 515 109 172 311
3 lost world (clark) 590 112 181 265
4 east wind (buck) 557 129 128 343
5 farewell to arms (hemingway) 589 72 129 339
6 sound and fury 7 (faulkner) 541 109 136 228
str(author1[,1:5])
'data.frame': 12 obs. of 5 variables:
$ : Factor w/ 12 levels "asia (michener)",..: 12 2 6 3 4 11 10 9 5 8 ...
$ a: int 550 515 590 557 589 541 517 592 576 557 ...
$ b: int 116 109 112 129 72 109 96 151 120 97 ...
$ c: int 147 172 181 128 129 136 127 251 136 145 ...
$ d: int 374 311 265 343 339 228 356 238 404 354 ...
ca(author1[,1:5])
Error in sum(N) : invalid 'type' (character) of argument
我想知道是否有一个简单的解决方法可以将author1 转换为源author。
【问题讨论】: