[R] Storing Variables of different types

jim holtman jholtman at gmail.com
Sat Sep 15 16:06:58 CEST 2007


One technique that I use (with POSIXct dates) is to convert the date
to numeric so that it can be stored in an array (which must have the
same mode for all variables) and then when I need it, just convert it
back as needed.  Here is an example:

> x <- as.POSIXct("2007-09-15 13:25")
> x
[1] "2007-09-15 13:25:00 GMT"
> x.numeric <- unclass(x)
> x.numeric
[1] 1189862700
attr(,"tzone")
[1] ""
> # back to POSIXct
> x.POSIXct <- ISOdate(1970,1,1,0) + x.numeric
> x.POSIXct
[1] "2007-09-15 13:25:00 GMT"
> # or you can just change the class
> structure(x.numeric, class=c("POSIXt", "POSIXct"))
[1] "2007-09-15 13:25:00 GMT"
>


On 9/14/07, Garavito,Fabian <fgaravito at guggenheimadvisors.com> wrote:
>
> Hi there,
>
> I have an ixjxk array where I want to store dates in the first column of
> all sub-matrices (i.e. j=1 is a column with dates) and real numbers in
> the rest of the columns.......I have been trying many things, but I am
> not getting anywhere.
>
> Thank you very much for your help,
>
> Fabian
>
>
> This message and any attachment are confidential and may be privileged or otherwise protected  from disclosure. If you are not the intended recipient, please telephone or email the sender and delete this message and any attachment from your system. If you are not the intended recipient you must not copy this message or attachment or disclose the contents to any other person. Nothing contained in the attached email shall be regarded as an offer to sell or as a solicitation of an offer to buy any  services, funds or products or an expression of any opinion or views of the firm or its employees. Nothing contained in the attached email shall be deemed to be an advise of, or recommendation by, the firm or its employees. No representation is made as to accuracy, completeness, reliability or appropriateness of the information contained in the attached email.
>
> ______________________________________________
> R-help at r-project.org 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.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list