Modérateur : Groupe des modérateurs
Code : Tout sélectionner
> t_list<-rep(list(sample(1:10000,size=3)),5000)
> t_list[1:2]
[[1]]
[1] 5766 9644 2244
[[2]]
[1] 5766 9644 2244
> t_mat<-do.call("rbind",t_list)
> t_mat[1:10,]
[,1] [,2] [,3]
[1,] 5766 9644 2244
[2,] 5766 9644 2244
[3,] 5766 9644 2244
[4,] 5766 9644 2244
[5,] 5766 9644 2244
[6,] 5766 9644 2244
[7,] 5766 9644 2244
[8,] 5766 9644 2244
[9,] 5766 9644 2244
[10,] 5766 9644 2244
> write.table(t_mat,"t_mat.txt",sep="\t",row.names=F)
> write.table(t_mat,"t_mat.xls",sep="\t",row.names=F)
Si par contre j'appelle
> do.call(rbind,listeGen)
pour l'avoir sous forme de matrice, R n'est pas content.
Code : Tout sélectionner
do.call("rbind", listeGen)
Code : Tout sélectionner
listeGen <- vector(mode = "list", length = n)
Code : Tout sélectionner
# soit res le contenant
res <- NULL
for (i in 1:500) {
for (j in 1:i-1) {
u <- c(i,j,cor(toto[i],toto[j],use="pairwise.complete.obs"));k=k+1;
res <- rbind(res,u)
}
}
is.matrix(res)
Code : Tout sélectionner
# soit res le contenant
res <- NULL
for (i in 1:500) {
for (j in 1:i-1) {
u <- c(i,j,cor(toto[i],toto[j],use="pairwise.complete.obs"));k=k+1;
res <- rbind(res,u)
}
}
is.matrix(res)
Code : Tout sélectionner
cor(toto)
Code : Tout sélectionner
> mat <- matrix(runif(100000), ncol = 5000)
> system.time(cormat <- cor(mat))
[1] 2.06 0.11 2.17 NA NA
>
> dim(cormat)
[1] 5000 5000
Code : Tout sélectionner
x <- matrix(rnorm(25),5,5,dimnames=list(as.integer(1:5),as.integer(1:5)))
x
1 2 3 4 5
1 0.18931202 -0.4579587 1.1740275 -0.4429264 -0.8397508
2 1.54449168 -0.8151885 0.5258326 -1.4049701 0.9094203
3 -0.02694955 1.3195234 -0.4664256 -0.4533051 0.2409488
4 2.59261257 0.2499363 1.2673197 -0.7765437 0.6929546
5 -1.27171641 -1.0478090 0.9086384 -1.9094488 1.3978522
corx <- cor(x,use="pairwise.complete.obs")
corx
1 2 3 4 5
1 1.00000000 0.1843643 0.2646658 0.3109222 -0.03874729
2 0.18436433 1.0000000 -0.6331019 0.7350265 -0.29892993
3 0.26466577 -0.6331019 1.0000000 -0.2024142 -0.04581440
4 0.31092224 0.7350265 -0.2024142 1.0000000 -0.83933118
5 -0.03874729 -0.2989299 -0.0458144 -0.8393312 1.00000000
class(corx) <- "table"
lower <- as.vector(lower.tri(corx))
corx <- as.data.frame.table(corx)
corx <- as.matrix(corx)
corx <- corx[lower,]
corx <- corx[,c(2,1,3)]
corx # une matrice de charactère mais pas de soucis pour la passée en nombre
Var2 Var1 Freq
2 "1" "2" " 0.18436433"
3 "1" "3" " 0.26466577"
4 "1" "4" " 0.31092224"
5 "1" "5" "-0.03874729"
8 "2" "3" "-0.63310194"
9 "2" "4" " 0.73502654"
10 "2" "5" "-0.29892993"
14 "3" "4" "-0.20241423"
15 "3" "5" "-0.04581440"
20 "4" "5" "-0.83933118"
Retourner vers « Questions en cours »
Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 1 invité