Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Entering data
- BtBB <- data.frame(
- 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"),
- CIBC = c(0.08375119, 0.13442541, 0.10052910, -0.08663862, 0.20144753, 0.11847390, -0.17023013),
- RBC = c(0.151981531, 0.192551770, 0.123652150, -0.075897308, 0.225488874, 0.129635743, -0.089722358),
- National = c(0.07069587, 0.14422579, 0.11880516, -0.18466828, 0.35276606, 0.15019255, -0.10634566),
- BMO = c(0.08911954, 0.16348998, 0.16057054, -0.04989048, 0.23680840, 0.04162783, -0.11333135),
- TD = c(0.097771953, 0.195319962, 0.108869357, -0.022878761, 0.220870206, 0.112201752, -0.078615071),
- BNS = c(0.130434783, 0.156108597, -0.001806413, -0.155934248, 0.335715562, 0.085072231, -0.161119329))
- BtBB_min <- apply(BtBB[-1], 1, which.min) # Finding Minimums
- #Adding scalar to min vector so column numbers match properly with BtBB dataframe
- BtBB_min <- BtBB_min + 1
- #Removing last entry since only minimums from prior years matter, not current years
- BtBB_min <- BtBB_min[-length(BtBB_min)]
- #Removing first row from data frame since we want to reference current years
- BtBB <- BtBB[-1,]
- #Creating output vector for for loop
- BtBB_ret <- vector("double", length = length(BtBB_min))
- #Nested For loop where I'm having issue generating a proper output
- for (h in seq_along(BtBB_ret)) {
- for (i in nrow(BtBB)) {
- for (j in seq_along(BtBB_min)) {
- BtBB_ret[h] <- BtBB[i,BtBB_min[j]]
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement