1
$\begingroup$
sapply(c(2:5), function(y){
x[y,]<-x[y,]-(x[1,]*x[y, 1]/x[1, 1])})

for (i in c(2:5)){
  x[i,]<-x[i,]-(x[1,]*x[i, 1]/x[1,1])}

Can someone explain to me why I am getting different results, I am coming from Python, I am not used to these apply functions of R

Thanks!

$\endgroup$
  • $\begingroup$ I get the same result from both pieces of code. Both give error messages. You need to tell us what x is. $\endgroup$ – G5W Sep 21 at 22:10
  • $\begingroup$ X is a 5x5 matrix; I realized later that Sapply takes the rows and puts them as columns that is why I was getting different results. Thanks for your reply! $\endgroup$ – Guneykan Ozkaya Sep 22 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.