[R] HELP me please with import of csv to R

William Dunlap wdunlap at tibco.com
Wed Jul 11 23:28:34 CEST 2012


Did you use read.table(filename, ..., dec=",") when importing
the data (so "30,3" is read as the number 30 and 3 tenths instead
of as the character string "30,3")?

Whenever importing data follow up by using str() or summary()
on its output, before doing any further analysis.  E.g.,
  > bad <- read.table(header=TRUE, text="x y\n1,1 2,1\n1 2\n")
  > str(bad)
  'data.frame':   2 obs. of  2 variables:
   $ x: Factor w/ 2 levels "1","1,1": 2 1
   $ y: Factor w/ 2 levels "2","2,1": 2 1
  > good <- read.table(header=TRUE, dec=",", text="x y\n1,1 2,1\n1 2\n")
  > str(good)
  'data.frame':   2 obs. of  2 variables:
   $ x: num  1.1 1
   $ y: num  2.1 2

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
> Behalf Of F86
> Sent: Wednesday, July 11, 2012 2:40 AM
> To: r-help at r-project.org
> Subject: Re: [R] HELP me please with import of csv to R
> 
> Thank you! It is fixed now.
> 
> However, now when I'm trying with hist(skatter)   i get this message:  Error
> in hist.default(skatter) : 'x' must be numeric
> 
> I don't know what I'm doing wrong but it worked perfectly on windows some
> weeks ago.
> 
> My data skater looks like this:
> 
> > skatter
>            Kommuner   Skatt
> 1          Botkyrka 32,23
> 2          Danderyd 29,45
> 3             Ekero 31,33
> 4           Haninge 31,88
> 5          Huddinge 32,05
> 6          Jarfalla 30,73
> 7           Lidingo 30,72
> 8             Nacka 30,71
> 9         Norrtalje 32,22
> 10          Nykvarn 32,05
> 11        Nynashamn 31,93
> 12            Salem    32
> 13          Sigtuna 32,08
> 14       Sollentuna  30,3
> -
> -
> -
> ..until 290
> 
> 
> Everything should be right since its a csv, the number of municipalities
> (Swedish: Kommuner) is 290 and all objects has a tax rate ( Skatt)
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Need-HELP-how-find-
> a-csv-file-tp4636019p4636119.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list