[R-SIG-Finance] Extracting numeric data from a mixed data .csv file
dae
dougedmunds at gmail.com
Sun May 26 23:53:49 CEST 2013
I have a .csv file that contains 191 columns, some of which are numeric
and others are character data.
I want to create an xts object, preserving the numerical data.
I am not concerned about saving the character data.
The date field is a character field in the 3rd column of the the .csv file,
in the format %Y-%m-%d.
These are the steps I took. I used some different variable names so
I could back up if I didn't get the result I was expecting:
I am curious to know of other approaches, other than combining some of the
lines, or if there
are problems with this approach.
---code---
library("quantmod")
x = "mixed_data.csv"
x1.csv = read.csv(x, sep=',', as.is=TRUE)
x.dates = as.POSIXct(x1.csv[,3], format="%Y-%m-%d")
x2.csv = lapply(x1.csv,as.numeric) #generates a list with NAs for all chr
fields
x3.csv = data.frame(x2.csv)
x.zoo = zoo(x3.csv, order.by=x.dates)
x.xts = xts(x.zoo)
---end code---
--
View this message in context: http://r.789695.n4.nabble.com/Extracting-numeric-data-from-a-mixed-data-csv-file-tp4668030.html
Sent from the Rmetrics mailing list archive at Nabble.com.
More information about the R-SIG-Finance
mailing list