[R] code to iterate function apply to matrix
umai88
agnes.ayang at gmail.com
Wed May 16 08:11:12 CEST 2012
I got this code below and i want to repeat the loop for 100 times..
x<-rnorm(60)
mat1<-matrix(x,nrow=15,ncol=4)
trim<-numeric(ncol(mat1))
win<-numeric(ncol(mat1))
ssd<-numeric(ncol(mat1))
for(j in 1:ncol(mat1))
{
n=length(mat1[,j])
alpha=0.1
k=floor(alpha*n)+1
r=k-(alpha*n)
i=k+1
m=n-k
y1<-sort(mat1[,j])
y<-y1[i:m]
x.low=(1-r)*y1[k+1]+r*y1[k]
x.upp=(1-r)*y1[n-k]+r*y1[n-k+1]
trim[j] =1/((1-2*alpha)*n)*(sum(y)+r*(y1[k]+y1[n-k+1]))
win[j]=1/n*(sum(y)+k*(x.low+x.upp))
ssd[j]<-sum((y-win[j])**2)+k*( (y1[k+1]-win[j])**2 + (y1[n-k]-win[j])**2 )
}
trim.mean<-matrix(trim, nrow=1)
win.mean<-matrix(win, nrow=1)
sum.sq.dev<-matrix(ssd, nrow=1)
--
View this message in context: http://r.789695.n4.nabble.com/code-to-iterate-function-apply-to-matrix-tp4630221.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list