Skip to content
Prev 247653 / 398503 Next

to append a column to a data frame, has I use loop/if in my case?

Here is how you should be creating your dataframe so that each element
has the proper mode:
'data.frame':   70 obs. of  3 variables:
 $ days   : num  14991 14990 14989 14988 14987 ... # notice is it numeric
 $ price  : num  0.626 0.184 0.836 1.595 0.33 ...
 $ regular: num  0 0 0 0 0 0 0 0 0 0 ...
'data.frame':   70 obs. of  3 variables:
 $ days   :Class 'Date'  num [1:70] 14991 14990 14989 14988 14987 ...#
here it is 'Date'
 $ price  : num  0.626 0.184 0.836 1.595 0.33 ...
 $ regular: num  0 0 0 0 0 0 0 0 0 0 ...
days      price regular
1  2011-01-17 0.62645381       0
2  2011-01-16 0.18364332       0
3  2011-01-15 0.83562861       0
4  2011-01-14 1.59528080       0
5  2011-01-13 0.32950777       0
6  2011-01-12 0.82046838       0
7  2011-01-11 0.48742905       0
8  2011-01-10 0.73832471       0
On Mon, Jan 17, 2011 at 9:59 AM, Daniel Wu <daniel_wu_r at 163.com> wrote: