Displaying 20 results from an estimated 40000 matches similar to: "convert xts vector into matrix"
2012 May 29
2
Converting to XTS loses data.frame structure
Hello,
I noticed something odd when working with data frames and xts objects.
If I read in a CSV file, R creates a nice data.frame. This works well.
If I then convert to an XTS object, I see that all the values in the data are now quoted. My data is a mix of numeric and character. This is usually seen when converting a data.frame to a matrix, as R will treat all the data as the same class.
2012 Apr 06
1
Converting data frame to its object results in matrix of strings
Hi,
I have a rather large data frame (500 x 5000) that I want to convert to a proper xts object.
I am able to properly generate an xts object with the correct time index. However, all of my numerical values are now strings.
b <- as.xts(a[,2:dim(a)[2]], order.by=as.POSIXct(strptime(paste(a$Date), '%m/%d/%Y')))
My guess is that somewhere in the large data frame there are a few
2011 Jan 04
1
XTS : merge.xts seems to have problem with character vectors
Hi,
Please can you tell me what I am doing wrong. When trying to merge two xts
objects, one of which has multiple character vectors for columns...I am just
getting NAs.
> str(t)
POSIXct[1:1], format: "2011-01-04 11:45:37"
> y2 = xts(matrix(c(letters[1:10]),5), order.by=as.POSIXct(c(t + 1:5)))
> names(y2) = c(1,2)
> y2
1 2
2011-01-04 11:45:38
2009 Jun 01
0
Converting data.frame to xts
I have a data.frame object and I don't really understand how to made an xts
class out of it.
Consider:
> x <- data.frame(datetime, ltp, ltv)
> head(x, 2)
datetime ltp ltv
1 2009-05-05 07:30:01.604 899 1
2 2009-05-05 07:30:01.963 899 15
> class(x$datetime)
[1] "POSIXt" "POSIXct"
#This works for only one column and why do I lose the name
2009 Nov 12
1
xts conversion problem
I have two data frames, with two columns each, the first being a Date
variable. I would like to convert them to xts objects, indexed by the
Date column. I would like to use as.Date and not as.POSIXct as the
dateformat. The puzzling fact is that it works for the first one but
not the other. Here is a screenshot of the error:
> str(DF1)
'data.frame': 367 obs. of 2 variables:
$
2012 Jul 16
4
Error in as.xts
Hi
I got the following error using as.xts
Error in xts(x, order.by = order.by, frequency = frequency, ...) :
NROW(x) must match length(order.by)
Here is how the data looks like
> d1 <- read.csv(file.path(dataDir,"AppendixA-FishCountsTable-2009.csv"),
as.is=T)
> d1[1:3,]
dive_id date time species count size site depth level
TRANSECT VIS_M
1 62 10/12/2009
2009 Dec 19
1
as.xts convert all my numeric data to character
Hello, all... I've been playing with the TTR package and quantmod, and I'm
loading the Chicago Board of Exchange put/call ratio data via a simple
read.csv call...
CBOEtotal<-read.csv(file="
http://www.cboe.com/publish/ScheduledTask/MktData/datahouse/totalpc.csv
",skip=1)
this gives me a data frame with columns....
> names(CBOEtotal)
[1] "Trade_date"
2009 Feb 27
0
POSIXlt, POSIXct, strptime, GMT and 1969-12-31 23:59:59
R-devel:
Some very inconsistent behavior, that I can't seem to find documented.
Sys.setenv(TZ="GMT")
str(unclass(strptime("1969-12-31 23:59:59","%Y-%m-%d %H:%M:%S")))
List of 9
$ sec : num 59
$ min : int 59
$ hour : int 23
$ mday : int 31
$ mon : int 11
$ year : int 69
$ wday : int 3
$ yday : int 364
$ isdst: int 0
- attr(*, "tzone")= chr
2010 Dec 06
1
as.xts error
Dear all,
I am using the as.xts function to transfer a data frame to the xts
The following is the code and result:
a<-read.csv("price.csv")
a$Date<-as.POSIXct(a$Date)
str(a)
'data.frame': 15637 obs. of 2 variables:
$ Date : POSIXct, format: "2010-01-04 09:45:01" "2010-01-04 09:45:02"
"2010-01-04 09:45:03" ...
$ bid_hsi: int 21850
2010 Aug 17
0
Merge xts
Hi all ,
I have 12 xts objects of differing timeseries stamp. For example :
> str(s1_predict.xts)
An ?xts? object from 1990-03-25 20:00:00 to 1990-12-15 09:00:00 containing:
Data: num [1:725, 1] 11.23 10.18 9.3 9.74 10.18 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : NULL
Indexed by objects of class: [POSIXt,POSIXct] TZ:
Original class: 'double'
xts
2011 Jan 11
1
Interpolate xts
Hello,
I have a xts object, I would like to fill the NA with linear
interpolated data. Can anyone please help.
> str(zz)
An ‘xts’ object from 2010-11-24 15:59:29 to 2010-11-24 16:00:00 containing:
Data: num [1:23401, 1] 312 312 312 312 312 ...
Indexed by objects of class: [POSIXct,POSIXt] TZ:
xts Attributes:
List of 2
$ src : chr "datafeed"
$ updated: POSIXct[1:1],
2009 Sep 15
0
xts and data.frame question
Hello there!
does any one know how to convert the following type of data
> z
DATE TIME ISIN PRICE VOL ID_DEAL RANK
1881 2009-09-11 10:30:59 RTS-9.09 117445 10 98200801 1
1882 2009-09-11 10:31:59 RTS-9.09 117450 1 98202144 6
1883 2009-09-11 10:32:59 RTS-9.09 117285 1 98203075 1
1884 2009-09-11 10:33:59 RTS-9.09 117180 3 98203828 1
1885 2009-09-11
2012 Nov 02
2
override date in xts time series
Using the following bit of R, I'm wondering if there is a way to
override/manipulate/replace the date in one xts time series with the date of
another xts time series while not affecting/changing the times of the xts
time series?
library(xts)
x.Date <- rep("1/1/2004",times=5)
x.Times<- c("00:00:00", "00:15:00", "00:30:00",
2011 Mar 04
4
xts POSIXct index format
Hi,
I cannot figure out how to change the index format when displaying POSIXct
objects.
Would like the xts index to display as %H:%M:%OS3 when doing viewing the xts
object.
Think I am missing the obvious.
Cheers,
Chris
--
View this message in context: http://r.789695.n4.nabble.com/xts-POSIXct-index-format-tp3336136p3336136.html
Sent from the R help mailing list archive at Nabble.com.
2012 Apr 27
1
multivariate xts merge question
Hi,
I have an xts starting with a number of columns (currency pairs see below),
then I add new ones which are derived from existing ones (like adding the
moving average of a column) by merging the new columns one by one. These
get the name of the column they are calculated from concatenated with ".1".
All done by merge.xts, easy.
Now, I have a function (procState below) which generates
2012 Mar 04
1
Store vectors as values in xts time-series object
Hi R programmers,
I have stumbled across what seems a very simple problem. My goal is to
create a xts time series object which contains vectors as values. In
other words, I try to create something like this:
2009-01-01 => c('aa', 'bb', 'dd')
...
2010-02-01 => c('mm')
I have figured out parts of separately. Here's what works (new xts
time-series with
2011 Oct 03
1
xts/time-series and plot questions...
Hello,
I'm a complete newbie to R. Spent this past weekend reading The Art of R Programming, The R Cookbook, the language spec, Wikis and FAQs. I sort-of have my head around R; the dizzying selection of libraries, packages, etc? Not really. I've probably missed or failed to understand something...
I have very a simple data set. Two years (ish) of temperature data, collected and
2011 Mar 07
1
Associating the day of week to a daily xts object
I have the following xts objetct "temp"
> str(temp)
An ?xts? object from 2010-12-26 to 2011-03-05 containing:
Data: num [1:70, 1] 2.95 0.852 -0.139 1.347 2.485 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr "t_n"
Indexed by objects of class: [POSIXct,POSIXt] TZ: GMT
xts Attributes:
NULL
> temp
t_n
2010-12-26
2009 Apr 27
2
series at low freq expanded into high freq
Folks,
If I have a series mm of, say, monthly observations, and a series dd of
daily dates, what's a good way of expanding mm such that corresponding
to each day in dd within the corresponding month in mm, the values of mm
are repeated?
So e.g., if I have mm:
mm <- c(15, 10, 12, 13, 11)
names(mm)<-c("Nov 2008", "Dec 2008", "Jan 2009", "Feb
2010 May 17
1
Isn't aggreate.zoo supposed to work with POSIXct (zoo/TTR/xts issue)?
library(xts)
library(TTR)
ndx = getYahooData("^NDX")
aa = ndx$Close
bb = aggregate(aa, as.yearweek, tail, 1)
The last operation takes forever, and then the bb dates are messed up. The following produces the desired result:
time(aa) = as.Date(time(aa))
bb = aggregate(aa, as.yearweek, tail, 1)
The index of ndx and aa is of POSIXct (as reported by is(time(ndx))) , which apparently