############################## # Define matrix as column (document) array A <- matrix ( c( c (1, 1, 3, 4, 5), # First document c (3, 2, 1, 4, 3), c (1, 1, 3, 1, 2), c (2, 2, 4, 3, 5), c (3, 4, 3, 2, 1), c (3, 2, 3, 4, 4)), # Sixth document nrow = 5, # terms ncol = 6); # documents # Print matrix A A; # Plot two arbitrary coordinates plot (A[1,],A[2,]); ###################################### # Compute the principal component analysis PCA <- princomp (t(A)); # Print the relevant results of the PCA PCA$center; PCA$loadings; # Change the coordinates based on the eigenvector decomposition A1 <- (t(PCA$loadings[,1:2])) %*% (A - PCA$center); # Print the new coordinates A1; # Plot the two first (principal) coordinates in the new reference frame plot (A1[1,],A1[2,]);