Re: [R] using 'apply' to apply princomp to an array of datasets

2012-12-12 Thread David Romano
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 wrote: > Hello, > > As for the first question try > > scoreset <- lapply(pcl, function(x) x$scor

Re: [R] using 'apply' to apply princomp to an array of datasets

2012-12-12 Thread Rui Barradas
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

Re: [R] using 'apply' to apply princomp to an array of datasets

2012-12-12 Thread 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 wrote: > > Hi everyone, > > Suppose I have a 3D array of datasets, where say dimension 1 corresponds > to cases, dimension 2 to datasets, and dimension 3 to observatio

[R] using 'apply' to apply princomp to an array of datasets

2012-12-12 Thread David Romano
Hi everyone, Suppose I have a 3D array of datasets, where say dimension 1 corresponds to cases, dimension 2 to datasets, and dimension 3 to observations within a dataset. As an example, suppose I do the following: > x <- sample(1:20, 48, replace=TRUE) > datasets <- array(x, dim=c(4,3,2)) Here,