Outils logiciels pour les cours Paris II

Cours Paris II

Stages/ Thèses/ Séminaires

Laboratoire

edit SideBar

R

V <- c(1,2,3)

X <- matrix(c(1,2,3,4,5,6),nrow=2,ncol=3)

  • Matrice dans dans un fichier :

cat("1 2 3 4", "2 6 7 8", "3 10 11 12", file="f.dat", sep="\n")

  • Boucle

for(i in 1:5) print(1:i)

  • Matrix multiplication

B %*% C

  • PCA on a simple example
     [,1] [,2] [,3] [,4]

[1,]   0.1   2   2.0   1

[2,]   0.2   3   3.0   1

[3,]   0.1   4   4.1   1

 # initial matrix

B <- matrix(c(0.1,2,2,1,0.2,3,3,1,0.1,4,4.1,1), nrow = 3, ncol = 4, byrow = TRUE)

print(B)

 # covariance matrix

B.cov <- cov(B)

print(B.cov)

 # eigenvectors and eigenvalues

C <- eigen(B.cov)

V <- C$vectors; VP <- C$values

print("vecteurs propres"); print(VP)

print(V)

 # restrict to the first 2 dimensions

V1 <- V[1:4,1:2]

print(V1)

 # projection of the initial matrix

B1 <- B %*% V1

print(B1)

UP2