Home append elements to vector in R returns only latest value
Reply: 1

append elements to vector in R returns only latest value

Maya
1#
Maya Published in 2017-12-06 11:10:59Z

I would like to read through a for loop some data in a dataframe and create a ratio using them. The ratio is well calculated as the singular output is fine. However, I wish to create a vector out of the ratios. The issue is that the output of the vector is always the latest ratio. Could anybody help on that, please? Thanks.

for(i in seq(from = 0, to = nrow(newdata2018), by = 2)){
  ratio1vector <- NULL

  ratio1 <- newdata2018$A_01[i]/newdata2018$A[i]*100
  ratio1vector <- c(ratio1vector, ratio1)

  print(ratio1vector)
}
Maya
2#
Maya Reply to 2017-12-06 11:31:08Z

To solve the issue is sufficient to create the vector externally from the loop.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.347691 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO