Skip to content

using 'apply' to apply princomp to an array of datasets

4 messages · Rui Barradas, David Romano

#
Sorry, I just realized I didn't send the message below in plain text.
-David Romano
On Wed, Dec 12, 2012 at 9:14 AM, David Romano <dromano at stanford.edu> wrote:
#
Hello,

As for the first question try

scoreset <- lapply(pcl, function(x) x$scores[, 1])
do.call(cbind, scoreset)


As for the second question, you want to know which columns in 'datasets' 
have NA's?

colidx <- apply(datasets, 2, function(x) any(is.na(x)))
datasets[, colidx]  # These have NA's


For the column numbers you can do

colnums <- which(colidx)

Hope this helps,

Rui Barradas

Em 12-12-2012 17:14, David Romano escreveu:
#
Thank you, Rui!   This is incredibly helpful -- anonymous functions
are new to me, and I appreciate being shown how useful they are.

Best regards,
David
On Wed, Dec 12, 2012 at 10:12 AM, Rui Barradas <ruipbarradas at sapo.pt> wrote: