Skip to content

NROW doesn't equal length(x)

2 messages · R. Michael Weylandt

#
Your first problem is that you aren't using paste() properly: print
out paste(ct3[, 1:2]) and take a look at it.

This works:

apply(head(ct3[,1:2]),1,paste,collapse = " ")

You also have the format argument to POSIXct wrong. See ?strptime for details.

So the whole line (if you want to do it in one) would be something like this:

v = xts(ct3[,3], as.POSIXct(apply(ct3[, 1:2],1, paste, collapse = "
"), format = "%m/%d/%Y %H:%M:%S"))

head(v)

2011-02-22 09:31:13 19.46
2011-02-22 09:31:28 19.50
2011-02-22 09:31:43 19.55
2011-02-22 09:31:58 19.59
2011-02-22 09:32:13 19.67
2011-02-22 09:32:28 19.68

Michael

PS -- It's best practice to cc the list as well as me in replies so
that this gets archived.
On Tue, Nov 1, 2011 at 5:37 PM, Muhammad Abuizzah <izzah100 at yahoo.com> wrote:
#
I perhaps made that a little too complicated:

this will also work:

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

identical(v, v2)
TRUE

On Tue, Nov 1, 2011 at 6:06 PM, R. Michael Weylandt
<michael.weylandt at gmail.com> wrote: