I am quite new to R and I would appreciate any help.
I need to calculate eigenvalues of a series of matrices and then save them in a separate file. My data has 5 columns and 10,000 rows. To be able to calculate this, I need to separate the data into a series of 5 x 5 matrices. As an example please consider a data set with only 5 columns and 10 rows:
1 2 3 4 5
11 21 31 41 51
12 22 32 42 52
13 23 33 43 53
14 24 34 44 54
15 25 35 45 55
16 26 36 46 56
17 27 37 47 57
18 28 38 48 58
19 29 39 49 59
I have written the code below so far:
R<-NULL
A <- setwd("c:/location of the file on this computer")
for (i in 0:1){
X <- read.table(A, skip=i*5, nrow=5)
M <- as.matrix(X)
E <- eigen(M)
R<-rbind(R,E)}
}
The results should look something like: eigen() decomposition
$`values`
[1] 2.362320e+02+0.000000e+00i -4.960046e+01+1.258757e+01i -4.960046e+01-1.258757e+01i 9.689475e-01+0.000000e+00i
[5] 1.104994e-14+0.000000e+00i
$vectors
[,1] [,2] [,3] [,4] [,5]
[1,] 0.9351696+0i 0.95959917+0.00000000i 0.95959917+0.00000000i 0.05003956+0i -1.529602e-15+0i
[2,] 0.1382999+0i -0.07952624-0.04585480i -0.07952624+0.04585480i -0.00162525+0i 4.670542e-17+0i
[3,] 0.1451493+0i -0.09392247-0.04970605i -0.09392247+0.04970605i -0.21235137+0i -4.082483e-01+0i
[4,] 0.2521091+0i 0.11157105+0.16033279i 0.11157105-0.16033279i -0.70990185+0i 8.164966e-01+0i
[5,] 0.1473217+0i -0.13518414-0.05496162i -0.13518414+0.05496162i 0.66965637+0i -4.082483e-01+0i
However, the result I get from the current codes are:
> class(R)
[1] "matrix"
> print(R)
values vectors
E Complex,5 Complex,25
E Complex,5 Complex,25
I have a few questions and it would be a big help if you could help with any of them:
How to fix my problem?
Also, the output Excel file - the one created in the temporary folder - does not open in Excel.