[R] function to reduce resolution of a vector or matrix?

Carl Witthoft carl at witthoft.com
Fri Jun 3 17:42:26 CEST 2011


Hi,
I feel dumb even asking, but isn't there an R function somewhere that I 
can use to reduce the resolution of a vector (or matrix) by summing 
terms in uniform blocks?  That is, for a vector X, reduce it to some 
X.short as  X.short[1]<- sum(X[1:10]);  X.short[2] <- sum(X[11:20]), and 
so on.

I did the following:

X.short<-colSums(matrix(X,16,2048/16)) # X is of length 2048

but surely there's already  a function somewhere that does this in a 
more general case?  And, my approach will get a bit painful for reducing 
a matrix in both dimensions.

Carl



More information about the R-help mailing list