[R] putting a column name on a zoo object

Horace Tso Horace.Tso at pgn.com
Tue Nov 14 23:46:01 CET 2006


Mark, it's not the most elegant solution but here it is,

I have a zoo with a vector of numeric values,

> head(spc.z)
2000-01-03 2000-01-04 2000-01-05 2000-01-06 2000-01-07 2000-01-10 
   1455.22    1399.42    1402.11    1403.45    1441.47    1457.60 

> class(spc.z)
[1] "zoo"

Now I want to give it a name, 

z = zoo(data.frame(mydata=coredata(spc.z)), index(spc.z))

> head(z)
            mydata
2000-01-03 1455.22
2000-01-04 1399.42
2000-01-05 1402.11
2000-01-06 1403.45
2000-01-07 1441.47
2000-01-10 1457.60

HTH

H.


>>> "Leeds, Mark (IED)" <Mark.Leeds at morganstanley.com> 11/14/2006
1:49:24 PM >>>
I only have one column so when I try your suggestion, I get dsays,
"attempt to set colnames on object with less than two dimensions.
It is of class zoo but I guess something changes during that addition
that I am too much of a novice to understand.

This is what a dput gives. There is no dim in the dput which is
probably
what the problem is but I don't know how to fix it. Thanks.


structure(c(4.77126598671015, 4.7716359319335, 4.77176152623894, 
4.77196709472722, 4.77218067995761, 4.77213077515643, 4.77200790109121,

4.77203963822312, 4.7719973218234, 4.771903278968, 4.77183227075241, 
4.77182803831544, 4.77181216651724, 4.77182803831544, 4.77197193112401,

4.77198938729909, 4.77201612933324, 4.77202905929107, 4.7720184802471,

4.77188623275365, 4.77181745714463, 4.77187036187909, 4.77187036187909,

4.77187036187909, 4.77182803831544, 4.77182803831544, 4.77174338581391,

4.77179982161115, 4.77174338581391, 4.77182199194583, 4.77179417817475,

4.77174338581391, 4.77174338581391, 4.77179982161115, 4.77182803831544,

4.77182803831544, 4.77187036187909, 4.77191268365153, 4.7719338438661,

4.77191268365153, 4.77176690111649, 4.77188094249012, 4.77189857659306,

4.77212752040897, 4.77224143026734, 4.77240630536398), index =
structure(c(1144022520, 
1144022580, 1144022640, 1144022700, 1144022760, 1144022820, 1144022880,

1144022940, 1144023000, 1144023060, 1144023120, 1144023180, 1144023240,

1144023300, 1144023360, 1144023420, 1144023480, 1144023540, 1144023600,

1144023660, 1144023720, 1144023780, 1144023840, 1144023900, 1144023960,

1144024020, 1144024080, 1144024140, 1144024200, 1144024260, 1144024320,

1144024380, 1144024440, 1144024500, 1144024560, 1144024620, 1144024680,

1144024740, 1144024800, 1144024860, 1144024920, 1144024980, 1144025040,

1144025100, 1144025160, 1144025220), class = c("POSIXt", "POSIXct"
)), class = "zoo", .Names = c("1144022520", "1144022580", "1144022640",

"1144022700", "1144022760", "1144022820", "1144022880", "1144022940", 
"1144023000", "1144023060", "1144023120", "1144023180", "1144023240", 
"1144023300", "1144023360", "1144023420", "1144023480", "1144023540", 
"1144023600", "1144023660", "1144023720", "1144023780", "1144023840", 
"1144023900", "1144023960", "1144024020", "1144024080", "1144024140", 
"1144024200", "1144024260", "1144024320", "1144024380", "1144024440", 
"1144024500", "1144024560", "1144024620", "1144024680", "1144024740", 
"1144024800", "1144024860", "1144024920", "1144024980", "1144025040", 
"1144025100", "1144025160", "1144025220"))


-----Original Message-----
From: Leeds, Mark (IED) 
Sent: Tuesday, November 14, 2006 4:39 PM
To: 'Horace Tso'; r-help at stat.math.ethz.ch 
Subject: RE: [R] putting a column name on a zoo object

 let me try colnames. I thought I tried that earlier and got an error
but I've been wrong before.
 Thanks.


-----Original Message-----
From: Horace Tso [mailto:Horace.Tso at pgn.com] 
Sent: Tuesday, November 14, 2006 4:29 PM
To: Leeds, Mark (IED); r-help at stat.math.ethz.ch 
Subject: Re: [R] putting a column name on a zoo object

Mark,

What's wrong with the following,

> head(sp.z)
              Open    High     Low   Close     Volume Adj..Close.
2000-01-03 1469.25 1478.00 1438.36 1455.22  931800000     1455.22
2000-01-04 1455.22 1455.22 1397.43 1399.42 1009000000     1399.42
2000-01-05 1399.42 1413.27 1377.68 1402.11 1085500032     1402.11
2000-01-06 1402.11 1411.90 1392.10 1403.45 1092300032     1403.45
2000-01-07 1403.45 1441.47 1400.73 1441.47 1225200000     1441.47
2000-01-10 1441.47 1464.36 1441.47 1457.60 1064800000     1457.60

 colnames(sp.z)
[1] "Open"        "High"        "Low"         "Close"       "Volume"  

 
[6] "Adj..Close."

> colnames(sp.z)[1] = "OPEN"

> colnames(sp.z)
[1] "OPEN"    "High"        "Low"         "Close"       "Volume"     
[6] "Adj..Close."

HTH.

Horace W. Tso

 


>>> "Leeds, Mark (IED)" <Mark.Leeds at morganstanley.com> 11/14/2006
1:21:33 PM >>>
does anyone know how to put a column name on a zoo object. I think
achim
and gabor are off line or they have gotten totally tired of me an
decided to ignore me ( which is totalyy understandable ).

logbidask<-log((aggfxdata[,"bid"] + aggfxdata[,"ask"])/2.0) logbidask
doesn't have a name and I can't figure out how to get one on it ?

aggfxdata is a zoo object.
--------------------------------------------------------

This is not an offer (or solicitation of an offer) to
buy/se...{{dropped}}

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.
--------------------------------------------------------

This is not an offer (or solicitation of an offer) to buy/sell the
securities/instruments mentioned or an official confirmation.  Morgan
Stanley may deal as principal in or own or act as market maker for
securities/instruments mentioned or may advise the issuers.  This is not
research and is not from MS Research but it may refer to a research
analyst/research report.  Unless indicated, these views are the author's
and may differ from those of Morgan Stanley research or others in the
Firm.  We do not represent this is accurate or complete and we may not
update this.  Past performance is not indicative of future returns.  For
additional information, research reports and important disclosures,
contact me or see https://secure.ms.com/servlet/cls.  You should not use
e-mail to request, authorize or effect the purchase or sale of any
security or instrument, to send transfer instructions, or to effect any
other transactions.  We cannot guarantee that any such requests received
via e-mail will be processed in a timely manner.  This communication is
solely for the addressee(s) and may contain confidential information. 
We do not waive confidentiality by mistransmission.  Contact me if you
do not wish to receive these communications.  In the UK, this
communication is directed in the UK to those persons who are market
counterparties or intermediate customers (as defined in the UK Financial
Services Authority's rules).



More information about the R-help mailing list