[R] Data Frame Column Name Attribute

thomas mann twiniverse2000 at gmail.com
Sat Apr 23 17:59:06 CEST 2016


I am attempting to add a calculated column to a data frame.  Basically,
adding a column called "newcol2" which are the stock closing prices from 1
day to the next.

The one little hang up is the name of the column.  There seems to be an
additional data column name included in the attributes (dimnames?).  So
when i run HEAD(DATAFRAMENAME) i get the column name = "Open".   but you
can see below... it is called "newcol2 with some attribute called open.

I did a lot of google searches but really could not find what i was looking
for.  Any help is greatly appreciated.  Thank you!

tdata[["newcol2"]] <- rbind(0,apply(tdata["Open"],2,diff))

> str(tdata)
'data.frame': 7505 obs. of  8 variables:
 $ Date   : int  19860709 19860710 19860711 19860714 19860715 19860716
19860717 19860718 19860721 19860722 ...
 $ Open   : num  9.14 9.45 9.3 9.08 8.71 ...
 $ High   : num  9.45 9.51 9.35 9.08 8.71 ...
 $ Low    : num  9.03 9.14 9.03 8.65 7.96 ...
 $ Close  : num  9.4 9.35 9.03 8.76 8.5 ...
 $ Volume : int  332719 180049 234212 218772 605427 339507 306866 418593
94880 119332 ...
 $ OpenInt: num [1:7505, 1] 0 0.317 -0.155 -0.223 -0.367 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr "Open"
* $ newcol2:* num [1:7505, 1] 0 0.317 -0.155 -0.223 -0.367 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
*  .. ..$ : chr "Open"*

	[[alternative HTML version deleted]]



More information about the R-help mailing list