Hey guys, i have a strange problem reading a .csv file. Seems not to be covered by the usual read.csv techniques. The relevant data i want to use, seems to be saved as the label of the data point. Therefore i can not really use it spec<-"EU2001" part1<-"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_" part2<-"&csvformat=de&euro=mixed&tr=" tmp<-tempfile() load<-paste(part1,spec,part2,spec,sep="") download.file(load,tmp) file<-read.csv(tmp,sep=";",dec=",", skip="5") (relevant<-file[,2][1]) Thanks a lot for your help and your time! Regards -- View this message in context: http://r.789695.n4.nabble.com/Data-read-as-labels-tp4629901.html Sent from the R help mailing list archive at Nabble.com.
On Mon, May 14, 2012, at 02:33, barb wrote:> Hey guys, > > i have a strange problem reading a .csv file. > Seems not to be covered by the usual read.csv techniques. > > The relevant data i want to use, seems to be saved as the label of the > data > point. > Therefore i can not really use it > > > spec<-"EU2001" > part1<-"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_" > part2<-"&csvformat=de&euro=mixed&tr=" > tmp<-tempfile() > load<-paste(part1,spec,part2,spec,sep="") > download.file(load,tmp) > file<-read.csv(tmp,sep=";",dec=",", skip="5") > (relevant<-file[,2][1])It seems to me that there is a problem with conversion from data to known type - the last two lines contains comments instead of data and first column type is not recognized. You can supress all conversions, remove problematic lines and then make conversion manually or import only relevant lines and specify types. For example: file<-read.csv(tmp, sep=";", dec=",",skip=5,header=FALSE,nrows=495,colClasses=c("character","numeric","NULL","NULL")) -- Z pozdrowieniami, Krzysztof Mitko
On May 14, 2012, at 5:33 AM, barb wrote:> Hey guys, > > i have a strange problem reading a .csv file. > Seems not to be covered by the usual read.csv techniques. > > The relevant data i want to use, seems to be saved as the label of > the data > point. > Therefore i can not really use it > > > spec<-"EU2001" > part1<-"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_ > " > part2<-"&csvformat=de&euro=mixed&tr=" > tmp<-tempfile() > load<-paste(part1,spec,part2,spec,sep="") > download.file(load,tmp) > file<-read.csv(tmp,sep=";",dec=",", skip="5") > (relevant<-file[,2][1]) >If dec="," then you probably need read.csv2() (Since dec="," is the default I would remove that argument from the call. It seemed to succeed ) file<-read.csv2(tmp,sep=";", skip="5") (relevant<-file[,2][1]) [1] 10716,05 496 Levels: 10323,52 10391,38 10716,05 10929,62 11051,23 11329,50 11380,11 ... Methodik: Ab Januar 1993 einschl. der Zusch?tzungen f?r nichtmelde- pflichtigen Au?enhandel, die bis Dezember 1992 in den Erg?nzungen zum Au?enhandel enthalten sind. -- David Winsemius, MD West Hartford, CT
Hey David, thanks for your fast reply, i really appreciate that you answer so many posts. Unfortunately it?s not that easy. Try to operate with the output: e.g file<-read.csv2(tmp,sep=";",skip="5") a<-(relevant<-file[,2][1]) a*5 # or as.numeric(relevant<-file[,2][1]) a is saved in the workspace as a factor and the values i actually need are saved as the labels. (therefore my subject) Thank You! -- View this message in context: http://r.789695.n4.nabble.com/Data-read-as-labels-tp4629901p4629951.html Sent from the R help mailing list archive at Nabble.com.
Hello, Your data.frame has some noise in the last two rows. See if this works. #------------------- this is your code --------------- spec <- "EU2001" part1 <- "http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_" part2 <- "&csvformat=de&euro=mixed&tr=" tmp <- tempfile() load <- paste(part1, spec, part2, spec, sep="") download.file(load,tmp) # read it in, no conversion from strings to factors file <- read.csv(tmp, sep=";", dec=",", skip="5", stringsAsFactors=FALSE) # see it str(file) head(file) tail(file) # -----> problem # last two rows are messed up nr <- nrow(file) # see it without them tail(file[ -c(nr - 1, nr), ]) # remove the last two rows fl <- file[ -c(nr - 1, nr), ] (relevant <- fl[, 2]) Also, 'file' is the name of an R function, use something else, it can be confusing. Hope this helps, Rui Barradas Em 15-05-2012 11:00, r-help-request at r-project.org escreveu:> Date: Mon, 14 May 2012 02:33:54 -0700 (PDT) > From: barb<mainzel89 at hotmail.com> > To:r-help at r-project.org > Subject: [R] Data read as labels > Message-ID:<1336988034111-4629901.post at n4.nabble.com> > Content-Type: text/plain; charset=us-ascii > > Hey guys, > > i have a strange problem reading a .csv file. > Seems not to be covered by the usual read.csv techniques. > > The relevant data i want to use, seems to be saved as the label of the data > point. > Therefore i can not really use it > > > spec<-"EU2001" > part1<-"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_" > part2<-"&csvformat=de&euro=mixed&tr=" > tmp<-tempfile() > load<-paste(part1,spec,part2,spec,sep="") > download.file(load,tmp) > file<-read.csv(tmp,sep=";",dec=",", skip="5") > (relevant<-file[,2][1])