Dear all,
I've got many responses to my initial question, which is stated below.
However, from those responses it has become clear that I need to
rephrase my problem. All responses dealt with subscripting the data
matrix before 'apply' is run on it. But this is not want I wanted to do.
'apply' cycles through rows or columns of a matrix, and runs a function
on each row or column individually. Now, instead of focusing on each
individual row or column, I want to get rid of these rows or columns,
and run the function on the remaining matrix.
I could do this with a for loop, such as:
x<-matrix(rnorm(100),20,5)
for (i in 1:ncol(x)) print(mean(x[,-i]))
But for more complex problems this becomes tedious...
Any ideas would be highly appreciated, Christian
Dear all,
'Apply' is a great thing for running functions on rows or columns of a
matrix:
X <- rnorm(20, mean = 0, sd = 1)
dim(X) <- c(5,4)
apply(X,2,sum)
Is there a way to use apply for excluding rows or columns from a
matrix to run functions on the remaining rows or columns? I know, I
could do this with a 'for' loop, but 'apply' would be much easier and
quicker, and require less programming...
Cheers, Christian