[R] Data read as labels

Rui Barradas ruipbarradas at sapo.pt
Tue May 15 19:22:31 CEST 2012


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])



More information about the R-help mailing list