cvs - read.csv() in R with all character columns and one numeric column -


i having trouble importing cvs file r (using read.csv()).

i import csv data file data frame in r , set columns "value" character columns. "value"vector should numeric column. can me please?

i have done many times other files 1 reason not cooperate. problem might caused fact file european style (decimal "."). not sure.

this link file: https://www.dropbox.com/s/9kqjiy5phj9qkg3/albania_%2b.csv?dl=0

i gave @ file , seems badly formatted. there 3 issues:

  • every line starts unnecessary quote (").
  • every line ends unnecessary quote (").
  • quotes doubled reason. instead of "fieldvalue" have ""fieldvalue"" in file.

this workaround read file (don't worry warning you'll receive after first line):

 textfile<-readlines("albania_+.csv")  x<-gsub('"{2}','"',gsub('(^"|"$)',"",textfile))  res<-read.csv(text=x,stringsasfactors=false)  str(res)  #'data.frame': 544 obs. of  10 variables:  #$ country.or.area: chr  "albania" "albania" "albania" "albania" ...  #$ year           : int  2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 ...  #$ area           : chr  "urban" "urban" "urban" "urban" ...  #$ sex            : chr  "female" "female" "female" "female" ...  #$ age            : chr  "total" "0 - 4" "5 - 9" "10 - 14" ...  #$ record.type    : chr  "estimate - de facto" "estimate - de facto"     "estimate - de facto" "estimate - de facto" ...  #$ reliability    : chr  "final figure, complete" "final figure, complete" "final figure, complete" "final figure, complete" ...  #$ source.year    : int  2013 2013 2013 2013 2013 2013 2013 2013 2013 2013 ...  #$ value          : num  763925 39796 42761 55894 68627 ...  #$ value.footnotes: logi  na na na na na na ... 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -