Dear R users,
I would like to sort elements of a matrix by row and use this ordering to
also sort another matrix. I am trying to post-order the means of components
for a mixture model and would also like to do the same for the component
probabilities. This is what I have tried thus far, but I doubt whether its
efficient given the number of replications I am using:
mean.data <- matrix(rnorm(20,0,1),10,2)
probs <- runif(10)
prob.data <- cbind(probs,1-probs)
sorted.mean <- sorted.prob <- array(0, dim=dim(mean.data))
for(i in 1:nrow(mean.data)){
sorted.data[i,] <- mean.data[i,order(mean.data[i,])]
sorted.prob[i,] <- prob.data[i,order(mean.data[i,])]
}
Thanks,
Vumani
______________________________________________
[email protected] 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.