hello, i am wondering why this code is not working. So i have a table of close prices and i am trying to create a new column called 'triangle' where if the close price of next line is greater than the close price the previous one, assign a value of 2 else assign a value of 1. I am getting an argument of length zero and i do not understand why
for(n in 2:nrow(data)) {
if(data[n]$Close > data[n+1,]$Close) {
data$triangle[n] <- 1
}
else
{
data$triangle[n] <- 2
}
}