I wrote this line of code in order to get an indication if the IBM stock closed up or down per last day before the current day. I'm new to quantmod so i wrote this line of code based on my R knowledge but i got some strange results.What is wrong? I got a strange summary results and an indication fo duplicates. Here are my lines of code:
> IBM_TRAIN$LastDay_green<- ifelse((lag(IBM_TRAIN$IBM.Open,k=1) < lag(IBM_TRAIN$IBM.Close,k=1)),1,0)
> summary(IBM_TRAIN$LastDay_green)
Index LastDay_green
Min. :2007-01-03 Min. :0.0000
1st Qu.:2008-10-15 1st Qu.:0.0000
Median :2010-07-21 Median :1.0000
Mean :2010-07-21 Mean :0.5418
3rd Qu.:2012-04-24 3rd Qu.:1.0000
Max. :2014-01-30 Max. :1.0000
NA's :1769
Warning message:
In data.row.names(row.names, rowsi, i) :
some row.names duplicated: 15,17,19,23,25,27,29,33,35,37,39,43,45,47,49,53,55,57,61,63,65,67,71,73,75,77,81,83,85,87,91,93,95,97,101,103,105,107,111,113,115,119,121,123,125,129,131,133,135,139,141,143,145,149,151,153,155,159,161,163,165,169,171,173,175,179,181,183,185,189,191,193,197,199,201,203,207,209,211,213,217,219,221,223,227,229,231,233,237,241,245,247,249,251,255,257,259,261,265,267,269,271,275,277,279,281,285,287,289,291,295,297,299,301,305,307,309,311,315,317,319,321,325,327,329,333,335,337,339,343,345,347,349,353,355,357,359,363,365,367,369,373,375,377,379,383,385,387,389,393,395,397,399,403,405,407,409,413,415,417,419,423,425,427,429,433,435,441,443,445,447,451,453,455,457,461,463,465,467,471,473,475,477,483,485,491,493,497,499,501,503,507,509,511,513,517,519,521,525,527,529,531,535,537,539,541,545,547,549,551,555,557,559,563,565,567,569,573,575,577,579,583,585,587,589,593,595,597,601,603,605,607,611,613,615,617,621,623,625,627,631,633,635,637,641,643,645,647,651,653,655,657 [... truncated]
I can't comment so adding this as an answer. The index summary is because the result of first operation is an XTS.
I reckon this should give summary for the colums values only -
summary(coredata(IBM_TRAIN$LastDay_green) )