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

append elements to vector in R returns only latest value

user579
1#
user579 Published in June 19, 2018, 7:55 pm

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)
}
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO