Please keep the list in the loop for the archives:

The data provided looks like this:

V = structure(list(V1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), .Label = "02/22/2011", class = "factor"), V2 = structure(c(1L,
1L, 2L, 3L, 4L, 5L, 5L, 6L, 7L, 7L, 7L, 8L, 9L, 9L, 9L, 10L,
11L, 12L, 13L, 14L, 14L, 15L, 15L, 15L, 15L, 15L), .Label = c("09:29:30",
"09:30:00", "09:30:06", "09:30:15", "09:30:41", "09:30:42", "09:30:53",
"09:30:58", "09:31:30", "09:31:44", "09:31:50", "09:31:54", "09:32:01",
"09:32:04", "09:32:41"), class = "factor"), V3 = c(63.91, 63.91,
63.82, 63.89, 63.81, 63.81, 63.81, 63.81, 63.85, 63.88, 63.88,
63.89, 63.9, 63.9, 63.9, 63.87, 63.9, 63.85, 63.95, 63.84, 63.84,
63.83, 63.89, 63.87, 63.89, 63.89), V4 = c(100L, 300L, 435L,
100L, 100L, 100L, 100L, 200L, 100L, 100L, 100L, 100L, 100L, 100L,
400L, 100L, 100L, 100L, 142L, 100L, 100L, 18169L, 100L, 100L,
100L, 177L), V5 = c(10554L, 10854L, 11289L, 11389L, 11489L, 11589L,
11689L, 11889L, 11989L, 12089L, 12189L, 12289L, 12389L, 12489L,
12889L, 12989L, 13089L, 13189L, 13331L, 13431L, 13531L, 31700L,
31800L, 31900L, 32000L, 32277L), V6 = c(63.73, 63.73, 63.81,
63.81, 63.81, 63.81, 63.81, 63.81, 63.81, 63.81, 63.81, 63.87,
63.83, 63.83, 63.83, 63.85, 63.85, 63.85, 63.85, 63.84, 63.84,
63.89, 63.84, 63.84, 63.84, 63.85), V7 = c(63.97, 63.97, 63.96,
63.95, 63.9, 63.9, 63.9, 63.9, 63.86, 63.94, 63.94, 64, 63.91,
63.91, 63.91, 63.96, 63.96, 63.96, 63.96, 63.96, 63.96, 63.95,
63.9, 63.9, 63.9, 63.95), V8 = c(3526L, 3527L, 4094L, 5140L,
6549L, 9533L, 9549L, 9636L, 11022L, 11147L, 11148L, 11721L, 16963L,
16964L, 16965L, 18854L, 19843L, 20381L, 21496L, 22384L, 22385L,
28832L, 28833L, 28834L, 28835L, 28849L), V9 = c(0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L), V10 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L)), .Names = c("V1", "V2", "V3", "V4", "V5", "V6",
"V7", "V8", "V9", "V10"), class = "data.frame", row.names = c(NA,
-26L))

It can be made into an appropriate xts in one line

V = xts(V[,3:10], as.POSIXct(paste(V[,1],V[,2]), format = "%m/%d/%Y
%H:%M:%S"), unique=F)

Working from the inside out:

paste(V[,1],V[,2]) # pastes the date and time stamps together
as.POSIXct(...,format = ) # convert to a time object and specify format so R
can read it
xts(V[,3:10],...,unique = F) # convert to xts and tell R not to worry about
non-unique time stamps

As to your problems with reading in the data, I can't help unless you care
to provide an example of your input file. All I'll say is that Excel's
"Date" format doesn't really correspond to standard date objects so you'll
usually have to convert after reading things in.

Hope this helps,

Michael Weylandt


On Tue, Sep 20, 2011 at 2:02 PM, Muhammad Abuizzah <izzah100@yahoo.com>wrote:

> Thanks for the reply Michael, I was working on something else in my data
> that's the reason for the delay in my response.  I had looked at your
> advise when I gotten it and tryed it but I couldn't make it work. I am
> attaching a file of my raw data.  I had indicated earlier that I managed to
> concatenate the date and time into one field using excel then uploaded the
> file into R thinking that my issue would be resolved but it didn't.
>
> Although I saved the first field as date formate in excel, when R read it
> it was saved as character format.  I am assuming this could be part of the
> problem because the first column needs to be in a time/date format in R for
> xts to read it.
>
> I tried several pieces of code on the data which I managed to concatenate
> date and time into the first field using excel
> to convert the first column from character format to POSIXct format I
> used :   as.POSIXct(a5[,1], index.TZ = America/EST) #a5 was the data.frame
> with the date time concatenated
> For the entier record I tried:   as.xts(zxzx, index= 1:2, unique =F) ##
> zxzx is the name of the raw data in R.
>
> I am babbiling away, but I rather just send you the record.  And just to
> summarize it was uploaded from a txt file into R, the data has date and
> time in the first 2 fields, I was not able to create an xts object from
> the data.frame, time values are not unique.
>
> Need help
>
> Your help is well appreciated!!
>
>   *From:* R. Michael Weylandt <michael.weylandt@gmail.com>
> *To:* Muhammad Abuizzah <izzah100@yahoo.com>
> *Cc:* "r-help@r-project.org" <r-help@r-project.org>
> *Sent:* Monday, August 22, 2011 11:19 PM
> *Subject:* Re: [R] Duplicate Rows in xts
>
> Without example code or data I can't guarantee this is your problem, but
> have you looked at using xts(...,unique = F) instead of the default true.
>
> Alternatively, let us see what your data actually looks like to R (dput)
> and we'll help. But what you've got sounds like a problem in the date
> format, which is a little hard to see without knowing the exact way it's
> appearing in R.
>
> Michael
>
> On Mon, Aug 22, 2011 at 7:46 PM, Muhammad Abuizzah <izzah100@yahoo.com>wrote:
>
> I read enourmous comment about this questions stating that it was answered
> before.
> I have been looking for the answer for a week without luck !!!
> I searched the archives the xts. vignitte , googled for an answer but
> couldn't find one so her it is:
>
> the Vignette states that xts "doesn't inforce the duplicate row
> requirement" but yet when I try to bring in tick stock data from a data
> frame as.xts it complains that the string is in an ambigious format.
>
> The date and time were in two separate columns I corrected that using excel
> and put them both in one column and saved the file as a text file in which
> the first column became similar to the example below.  tried to read the
> table directly, didn't work, I brought in the data as a data.frame() then
> tried to convert it, that didn't work either
>
> bellow is an example of how my data looks it has more than 2 columns, but
> the important column is the first one,  the second column "xxx" is price:
>
> 2011-02-10 12:21:05     xxx
> 2011-02-10 12:21:05     xxx
>
> Then I found out that zoo would allow me to bring the data in with the
> duplicates it will ask you to fix it but atleast I would havce a zoo
> object.  I thought I could trick it this way by bring it as zoo, then
> convert it to xts with the as.xts function      that didn't work either
>
> I read a solution about using make.unique function I tried it with the code
> bellow, that didn't work
>
> aapl<- make.index.unique(as.xts(read.table("C:\\Data Files\\new\\aapl.txt
> ")))
>
> part of the confusion with the "unique" function was should I wrape the
> xts object with it or should I wrap it (unique) within the xts, I didn't
> know the order so I tried both, and neithe worked
>
> So I gave up !!How can I bring in a txt file into R as an xts object when
> I have duplicate rows on seconds knowing I dont have fractions of seconds?
> Do we have to use the unique function or is it true that xts doesn't
> enforce the unique date requirement?
>
> Please provide code example based on the code line in blue and (aapl stock
> data) and date format above.
>
> Thanks in advance
>
> ______________________________________________
> R-help@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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
>

	[[alternative HTML version deleted]]

