Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #Entering data
  2. BtBB <- data.frame(
  3. Date = as.Date(c("2012-12-31", "2013-12-31", "2014-12-31", "2015-12-31", "2016-12-31", "2017-12-31", "2018-12-31"), format = "%Y-%m-%d"),
  4. CIBC = c(0.08375119, 0.13442541, 0.10052910, -0.08663862, 0.20144753, 0.11847390, -0.17023013),
  5. RBC = c(0.151981531, 0.192551770, 0.123652150, -0.075897308, 0.225488874, 0.129635743, -0.089722358),
  6. National = c(0.07069587, 0.14422579, 0.11880516, -0.18466828, 0.35276606, 0.15019255, -0.10634566),
  7. BMO = c(0.08911954, 0.16348998, 0.16057054, -0.04989048, 0.23680840, 0.04162783, -0.11333135),
  8. TD = c(0.097771953, 0.195319962, 0.108869357, -0.022878761, 0.220870206, 0.112201752, -0.078615071),
  9. BNS = c(0.130434783, 0.156108597, -0.001806413, -0.155934248, 0.335715562, 0.085072231, -0.161119329))
  10.  
  11. BtBB_min <- apply(BtBB[-1], 1, which.min) # Finding Minimums
  12.  
  13.  
  14. #Adding scalar to min vector so column numbers match properly with BtBB dataframe
  15. BtBB_min <- BtBB_min + 1
  16.  
  17. #Removing last entry since only minimums from prior years matter, not current years
  18. BtBB_min <- BtBB_min[-length(BtBB_min)]
  19.  
  20. #Removing first row from data frame since we want to reference current years
  21. BtBB <- BtBB[-1,]
  22.  
  23. #Creating output vector for for loop
  24. BtBB_ret <- vector("double", length = length(BtBB_min))
  25.  
  26.  
  27. #Nested For loop where I'm having issue generating a proper output
  28. for (h in seq_along(BtBB_ret)) {
  29. for (i in nrow(BtBB)) {
  30. for (j in seq_along(BtBB_min)) {
  31. BtBB_ret[h] <- BtBB[i,BtBB_min[j]]
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement