Code transformation to create a valid loop

I have this data-set that I am working with, which contains forex tick-data for the month of January 2015. The first step of my exercise is to manipulate the data-set into a functional form. The (working) code is:

data1<-read.csv("EURAUD_201501.csv", header = FALSE, col.names = c("TIMESTAMP", "BID", "OFR", "VOL"), stringsAsFactors = FALSE)  data1$VOL<- NULL  #drops the VOL column  data1$TIMESTAMP = sub( '(?<=.{11})', ':', data1$TIMESTAMP, perl=TRUE ) #manipulate the strings to create clear timestamps  data1$TIMESTAMP = sub( '(?<=.{14})', ':', data1$TIMESTAMP, perl=TRUE )  data1$TIMESTAMP = sub( '(?<=.{17})', '.', data1$TIMESTAMP, perl=TRUE )  options(digits.secs = 3)  xts_data1 = xts(data1[,c(2,3)], order.by = as.POSIXct(data1$TIMESTAMP, tz = "EST", format = "%Y%m%d %H:%M:%OS")) #Convert file to an xts object  rm(data1) #remove data1 object in order to save space 

I want to repeat this procedure 12 times for 12 months worth of data. My (failed) try to create a functional loop reads.

#Entering and editing data by hand# data<- c("data1", "data2","data3", "data4", "data5", "data6", "data7",        "data8", "data9", "data10", "data11", "data12")  real_data<- c("EURAUD_201501.csv", "EURAUD_201502.csv", "EURAUD_201503.csv", "EURAUD_201504.csv",               "EURAUD_201505.csv", "EURAUD_201506.csv", "EURAUD_201507.csv", "EURAUD_201508.csv",               "EURAUD_201509.csv", "EURAUD_201510.csv", "EURAUD_201512.csv", "EURAUD_201512.csv")  xts_data<- c("data1_xts", "data2_xts", "data3_xts", "data4_xts", "data5_xts", "data6_xts",              "data7_xts", "data8_xts", "data9_xts", "data10_xts", "data11_xts", "data12_xts")  for (i in 1:2) {data[i]<-read.csv("EURAUD_201501.csv", header = FALSE, col.names = c("TIMESTAMP", "BID", "OFR", "VOL"), stringsAsFactors = FALSE)  data[i]$VOL<- NULL  #drops the VOL column  data[i]$TIMESTAMP = sub( '(?<=.{11})', ':', data[i]$TIMESTAMP, perl=TRUE ) #manipulate the strings to create clear timestamps  data[i]$TIMESTAMP = sub( '(?<=.{14})', ':', data[i]$TIMESTAMP, perl=TRUE )  data[i]$TIMESTAMP = sub( '(?<=.{17})', '.', data[i]$TIMESTAMP, perl=TRUE )   xts_data[i] = xts(real_data[i][,c(2,3)], order.by = as.POSIXct(data2$TIMESTAMP, tz = "EST", format = "%Y%m%d %H:%M:%OS")) #Convert file to an xts object  rm(data[i]) } 

What is that I am doing wrong. Thank you in advance.

Replay

Category: r Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.249 (s). 12 q(s)