Dear all,

 

I have a huge problem after downloading and exporting data from Reuters3000
XTra:

 

I downloaded many many monthly, quarterly and yearly data. I do not know
why, but after saving, I have mixed-data sets, i.e. files which can be
imported as “read.csv” and others that are in the format of “read.csv2”.
Sure I could change them, but normally it should be possible to mix them…

 

For my analysis I decided to work with data.frames. Maybe this was the first
error of mine. (Any other suggestions?)

 

I want the following: Go through a folder, load all the data available (if
relevant input is in the file), put them all together in one single object
(data.frame) with the first column just the dates (especially for drawing
graphs) and all other columns with data. Row-wise the data and the date
should match. 

After that I want to compute the log-returns and do the analysis. One is an
univariate analysis, in another one, I want to perform PCA and other
multivariate analysis. So I need subsets of the huge file.

Maybe anybody’s got a better solution: a solution at all.

 

I cannot handle this…

 

It would be very, very appreciate if anybody could answer.

 

Thanks a lot and have a nice evening.

 

Regards,

Thomas

 

Please find enclosed the code:

 

##########################################################

####################### start of code #######################

##########################################################



# lade nötige Pakete

require(ff)

require(ts)

require(date)

require(pheno)

# Lege globale Variablen an

Pfad<-"I:\\Dokumente und Einstellungen\\Administrator\\Eigene
Dateien\\commodity analyse\\csv-dateien\\"

auslagerung<-"I:\\Auslagerung\\"

dir.create(auslagerung,showWarnings=F)

# Lege alle Dateienamen des Ordners "Pfad" in einen array ab

dateinamen<-list.files(Pfad)

#Schleife, die über alle Dateien in dateinamen geht.

#Sortiert alle Leerdateien aus, also Dateien ohne sinnvollen Input

for (i in 1:length(dateinamen)){

  input_teil<-NA

  try(input_teil<-read.csv2(paste(Pfad,dateinamen[i],sep="")))

  if(dim(input_teil)[2]<=1)
try(input_teil<-read.csv(paste(Pfad,dateinamen[i],sep="")))

  if(is.na(input_teil[1,1])){

    file.copy(paste(Pfad,dateinamen[i],sep=""),
paste(auslagerung,dateinamen[i],sep=""))

    file.remove(paste(Pfad,dateinamen[i],sep=""))

  }

}

dateinamen<-list.files(Pfad)

startdatum<-data.frame(NA,nrow=1,ncol=length(dateinamen))

enddatum<-data.frame(NA,nrow=1,ncol=length(dateinamen))

beobachtungen<-data.frame(NA,nrow=1,ncol=length(dateinamen))

#Nehme Dir nun die Dateien zur Brust und schreibe Länge der Datei,
Anfangsdatum, Enddatum

for (i in 1:(length(dateinamen))){

  try(input_teil<-read.csv2(paste(Pfad,dateinamen[i],sep="")))

  if(dim(input_teil)[2]<=1)
try(input_teil<-read.csv(paste(Pfad,dateinamen[i],sep="")))

  startdatum[i]<-as.character(input_teil[1,1])

  #diese Schleife packt sich immer die letzte Zeile, schaut ob das Datum
befüllt ist und schmeisst die Datei weg, wenn's nicht so ist

    for(k in 1:dim(input_teil)[1]){


if(input_teil[dim(input_teil)[1],1]==""|is.na(input_teil[dim(input_teil)[1],
1])) input_teil<-input_teil[1:(dim(input_teil)[1]-1),] else
k=dim(input_teil)[1]+1

    }

  enddatum[i]<-as.character(input_teil[dim(input_teil)[1],1])

  beobachtungen[i]<-dim(input_teil)[1]

}

# Und wandle nun die ganze Kacke in Daten um

for(i in 1:length(dateinamen)){

  startdatum[i]<-as.date(startdatum[[i]])

  enddatum[i]<-as.date(enddatum[[i]])

}



#Baue einen Datensatz





laenge

complete_history<-data.frame(NA,nrow=laenge, ncol=length(dateinamen)+1)

#1. Spalte: von niedrigsten Startdatum bis höchsten Enddatum

complete_history[,1]<-

#2. bis n. Spalte: Close-Price mit Überschrift und passendem Datum



##########################################################

######################## end of code ########################

##########################################################


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to