Thanks, Stefan, I'll take a look! Also, I figured out another solution (~15 minutes after posting :-/):
``` row_normalized_P <- Matrix::Diagonal(x = 1 / sqrt(Matrix::rowSums(P^2))) %*% P ``` Cheers, -m On Thu, May 4, 2017 at 12:23 PM, Stefan Evert <stefa...@collocations.de> wrote: > > > On 4 May 2017, at 20:13, Murat Tasan <mmu...@gmail.com> wrote: > > > > The only semi-efficient method I've found around this is to `apply` > across > > rows (more accurately through blocks of rows coerced into dense > > sub-matrices of P), but I'd like to try to remove the looping logic from > my > > codebase if I can, and I'm wondering if perhaps there's a built-in in the > > Matrix package (that I'm just not aware of) that helps with this > particular > > type of computation. > > The "wordspace" package has an efficient C-level implementation for this > purpose: > > P.norm <- normalize.rows(P) > > which is a short-hand for > > P.norm <- scaleMargins(P, rows=1 / rowNorms(P, method="euclidean")) > > Best, > Stefan [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.