I have a data frame that looks like this sx16 data frame:
Incase the link doesnt work:
The data frame is called sx16
It has column names: Date, Open, High, Low, Settle
I want to add a column called up_period that prints a 1 if the below calc is positive and a 0 if the below calc is negative:
sx16$Settle[ 1: nrow(sx16)] - sx16$Settle[ 2: nrow(sx16)]
Of course, this produces an error as the new list is shorter than the original sx16.
I have tried to wrap rbind.fill around it like so:
sx16$up_period <- rbind.fill(sx16$Settle[ 1: nrow(sx16)] - sx16$Settle[ 2: nrow(sx16)])
But this produces the following error:
Warning message: In sx16$Settle[1:nrow(sx16)] - sx16$Settle[2:nrow(sx16)] : longer object length is not a multiple of shorter object length
Of course, that is exactly what I thought rbind.fill would solve. Here is where I am stuck. Once I get this, I can add a simple if-else to do the 1 and 0, but I cannot figure out how to add this shorter column to my data frame.