Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8415931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:35:31+00:00 2026-06-10T01:35:31+00:00

Asked this question question recently and was advised to use the ‘ to.minutes5() ‘

  • 0

Asked this question question recently and was advised to use the ‘to.minutes5()‘ function. However, upon doing so I get the following error:

Error in to.period(x, "minutes", k = 5, name = name, ...) : 
unsupported type

My original text file has the date and time as to separate columns:

GBPUSD<- read.table("GBPUSD.txt", sep=',')

head(GBPUSD)

  V1           V2     V3     V4     V5     V6      V7    V8               
1 <TICKER> <DTYYYYMMDD> <TIME> <OPEN> <HIGH>  <LOW> <CLOSE> <VOL> 
2   GBPUSD     20010102 230100 1.5021 1.5021 1.5018  1.5018     4   
3   GBPUSD     20010102 230200 1.5019 1.5019 1.5019  1.5019     4     
4   GBPUSD     20010102 230300 1.5018 1.5019 1.5018  1.5019     4     
5   GBPUSD     20010102 230400 1.5019 1.5019 1.5019  1.5019     4     
6   GBPUSD     20010102 230500 1.5017 1.5018 1.5017  1.5018     4   

So the first step I undertook was to blend them into one column using the paste() function in a new ‘TIME’ column:

GBPUSD$Time <-paste(GBPUSD[,2],GBPUSD[,3],sep=",") 

After which I created a POSIXct time stamp using the new merged ‘TIME’ (9th column):

time<- as.POSIXct(GBPUSD[,9], format="%Y%m%d,%H%M%S")

Then I got around to creating an xts time series using the closing prices and time:

gbp<- xts(GBPUSD[7], time)

However, when I call to.minutes5(gbp), I get an error.

How do I convert the one minute closing prices in my text file to 5 minute prices without running a loop?

Additionally, how would I go about converting 1min OHLC to 5min OHLC?

UPDATE:

When I try the advice put forth by khoxsey, I get an error on the following line:

raw_cable <- read.table(header=FALSE, text=data, col.names=cn, colClasses=cl)
"Error in textConnection(text) : invalid 'text' argument"

I presume this happens because I first imported a tabular data frame and deleted the first line:

data<- read.table("GBPUSD.txt", sep=',')
data <- data[-1,] #deleted the initial header to add at a later step, as suggested
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:35:32+00:00Added an answer on June 10, 2026 at 1:35 am

    You’re not quite providing all of your code, so it’s hard to tell exactly where you’re going wrong, but you’re very close. I copied some of your data to get a few more observations and used your formatting to get the time string. (BTW, time is a function in R so you might call your variable something else).

    The first chunk of code is optional, simply some setup to get a data frame containing representative data, and call your setup to as.POSIXct to create our index:

    forex_data <- "GBPUSD 20010102 230000 1.5021 1.5021 1.5018 1.5018 4
    GBPUSD 20010102 230100 1.5021 1.5021 1.5018 1.5018 4
    GBPUSD 20010102 230200 1.5019 1.5019 1.5019 1.5019 4
    GBPUSD 20010102 230300 1.5018 1.5019 1.5018 1.5019 4
    GBPUSD 20010102 230400 1.5019 1.5019 1.5019 1.5019 4
    GBPUSD 20010102 230500 1.5017 1.5018 1.5017 1.5018 4
    GBPUSD 20010102 230600 1.5019 1.5019 1.5019 1.5019 4
    GBPUSD 20010102 230700 1.5018 1.5019 1.5018 1.5019 4
    GBPUSD 20010102 230800 1.5019 1.5019 1.5019 1.5019 4
    GBPUSD 20010102 230900 1.5017 1.5018 1.5017 1.5018 4
    GBPUSD 20010102 231000 1.5017 1.5018 1.5017 1.5018 4"
    
    cn <- c('TICKER','DTYYYYMMDD','TIME','OPEN','HIGH','LOW','CLOSE','Volume')
    cl <- c(rep('character', 3), rep('numeric', 5))
    raw_cable <- read.table(header=FALSE, text=forex_data, col.names=cn, colClasses=cl)
    
    dt_tm <-as.POSIXct(paste(raw_cable[,2], raw_cable[,3],sep=","), format="%Y%m%d,%H%M%S")
    

    Now that we have a data.frame containing our data, and an appropriate index vector, we create an xts object using only the price and volume data. Here, that means the last 5 columns.

    require(xts)  
    cable <- xts(raw_cable[,4:8], order.by=dt_tm)
    

    Finally, with a well-formed xts object, it is really easy to roll up to 5-minute periods. See the docs for to.period for a bunch of other possibilities. One key thing to note here is setting the indexAt parameter, which allows us to choose which ending minute to use. For fun, try out the other possibilities in the documentation.

    to.minutes5(cable, indexAt='startof', name=NULL)
    
                          Open   High    Low  Close Volume
    2001-01-02 23:00:00 1.5021 1.5021 1.5018 1.5019     20
    2001-01-02 23:05:00 1.5017 1.5019 1.5017 1.5018     20
    2001-01-02 23:10:00 1.5017 1.5018 1.5017 1.5018      4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently in a job interview I was asked this following question (for Java): Given:
I recently asked this question on here and got the answer. However I'm now
I recently asked this question: Compiler error referencing custom C# extension method Marc Gravell
I was recently asked this question in an interview. Lets suppose I have 2000
I was recently asked this question : What is the difference between String and
Recently I was asked this question in an interview. I gave an answer in
I recently asked this question: MS SQL share identity seed amongst tables (Many people
Note: I originally asked this question about an hour ago but only recently realized
I asked this question earlier: How to get delta between two text items But
I was asked this question recently during my job interview, and I couldn't answer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.