Re: [R] replacing values in a matrix or data.frame

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.ac.be>
Date: Mon 05 Jul 2004 - 19:53:23 EST

Hi,

you could try something like this,

x <- matrix(sample(1:10,25, rep=TRUE), 5 ,5) x

apply(x, 2, function(y){
  a <- table(y)
  rep(a/sum(a), a)
})

I hope this helps.

Best,
Dimitris



Dimitris Rizopoulos
Doctoral Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


>
>
> Hi,
>
> I have a matrix where I want to replace the entries of each column
by the
> proportion value of the times each entrie appears in that column,
that is, In
> each column there 4 to 10 repeated values, for wich i can compute
frequencies
> in the respective column, and then i want to replace each value for
its
> respective frequencie in another matrix. Can someone help me?
>
> Thanks for all the help.
> __________________________________________________________
> Quanto gasta de Acesso Ó Internet? Faša as contas!
> http://acesso.portugalmail.pt/contas
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jul 05 19:57:37 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:54:41 EST