assuncao.senra@portugalmail.com
2004-Jul-05 09:32 UTC
[R] replacing values in a matrix or data.frame
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
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 ----- Original Message ----- From: <assuncao.senra at portugalmail.com> To: <r-help at stat.math.ethz.ch> Sent: Monday, July 05, 2004 11:32 AM Subject: [R] replacing values in a matrix or data.frame> > > Hi, > > I have a matrix where I want to replace the entries of each columnby 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 computefrequencies> in the respective column, and then i want to replace each value forits> 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 at 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