[R] Mental Block with PCA of multivariate time series!

Gavin Simpson gavin.simpson at ucl.ac.uk
Mon May 16 11:14:39 CEST 2005

Laura Quinn wrote:
> Please could someone point me in the right direction as I appear to be
> having a total mental block with fairly basic PCA problem!
> I have a large dataframe where rows represent independent
> observations and columns are variables. I am wanting to perform PCA
> sequentially on blocks of nrows at a time and produce a graphical output
> of the loadings for the first 2 EOFs for each variable.
> I'm sure I've performed a very similar routine in the past, but the method
> is currently escaping me.
> Any help gratefully received!

Hi Laura,

iris.dat <- iris[,1:4]
pca.1 <- prcomp(iris.dat[1:50, ], scale = TRUE)
pca.2 <- prcomp(iris.dat[51:100, ], scale = TRUE)
pca.3 <- prcomp(iris.dat[100:150, ], scale = TRUE)


There is a better way of subsetting this data set as the 5th col of iris 
is a factor and we could use the subset argument to prcomp to do the 
subsetting without having to know that there are 50 rows per species. 
Take a look at that argument if you have a variable that defines the 
blocks for you.

Is this what you were after?

All the best,

Gavin Simpson                     [T] +44 (0)20 7679 5522
ENSIS Research Fellow             [F] +44 (0)20 7679 7565
ENSIS Ltd. & ECRC                 [E] gavin.simpsonATNOSPAMucl.ac.uk
UCL Department of Geography       [W] http://www.ucl.ac.uk/~ucfagls/cv/
26 Bedford Way                    [W] http://www.ucl.ac.uk/~ucfagls/
London.  WC1H 0AP.

More information about the R-help mailing list