In this case you could use the apply function.
Let your k*l matrix is named as y. Then, in order to standardize the values
within each column use the following function
aver<-apply(y,2,mean) # calculate the mean within each column
std<-apply(y,2,sd) # calculate the stabdard deviation within each column
z<-matrix(0,nrow=k,ncol=l)
for(i in 1:k){
for(j in 1:l){
z[i,j]<-(y[i,j]-aver[j])/std[j]
}
}
z
On Tue, Oct 2, 2012 at 12:51 PM, Rui Esteves wrote:
> Hello,
>
> I have a matrix with values, with columns c1..cn.
> I need the values to be normalized between 0 and 1 by column.
> Therefor, the 0 should correspond to the minimum value in the column c1 and
> 1 should correspond to the maximum value in the column c1.
> The remaining columns should be organized in the same way.
>
> Does a function in R exists for this purpose?
>
> Thanks,
> Rui
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]