Reputation: 695
I'm trying to transform tick-data to minute data.
dolar_1min_xts <- xts()
print(dolar_for_manipulation_xts)
[1]
Price
2018-02-01 09:00:57 "3203.0"
2018-02-01 09:00:57 "3203.5"
2018-02-01 09:00:57 "3203.5"
2018-02-01 09:00:57 "3203.5"
2018-02-01 09:00:57 "3203.5"
2018-02-01 09:00:57 "3203.5"
[...]
dolar_1min_xts <- to.period(dolar_for_manipulation_xts, period = "minutes", k = 1)
Error in to.period(dolar_for_manipulation_xts, period = "minutes", : unsupported type
Any tips on how I solve this?
For reproduction:
dolar_for_manipulation_xts
structure(c("3203.0", "3203.5", "3203.5", "3203.5", "3203.5",
"3203.5"), class = c("xts", "zoo"), .indexCLASS = c("POSIXct",
"POSIXt"), tclass = c("POSIXct", "POSIXt"), .indexTZ = "", tzone = "", index = structure(c(1517482857,
1517482857, 1517482857, 1517482857, 1517482857, 1517482857), tzone = "", tclass = c("POSIXct",
"POSIXt")), .Dim = c(6L, 1L), .Dimnames = list(NULL, "Price"))
Upvotes: 0
Views: 505
Reputation: 5398
I checked out the documentation at https://www.rdocumentation.org/packages/xts/versions/0.11-2/topics/to.period
and ran the sample code
data(sample_matrix)
samplexts <- as.xts(sample_matrix)
to.monthly(samplexts)
str(samplexts)
An ‘xts’ object on 2007-01-02/2007-06-30 containing: Data: num [1:180, 1:4] 50 50.2 50.4 50.4 50.2 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr [1:4] "Open" "High" "Low" "Close" Indexed by objects of class: [POSIXct,POSIXt] TZ: xts Attributes: NULL
and compared to your data
str(dolar_for_manipulation_xts)
An ‘xts’ object on 2018-02-01 06:00:57/2018-02-01 06:00:57 containing: Data: chr [1:6, 1] "3203.0" "3203.5" "3203.5" "3203.5" "3203.5" "3203.5" - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr "Price" Indexed by objects of class: [POSIXct,POSIXt] TZ: xts Attributes: NULL
and noticed your data are chr (strings), and not num!
I changed to numeric by removing the quotes ("3203.0") around the numbers and the function worked properly.
Upvotes: 1