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

William Dunlap wdunlap at tibco.com
Thu Jul 12 01:23:27 CEST 2012


You or nabble left out my suggestion to use dec="," in your
call to read.table (or read.csv, etc.)

  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")?

along with an example of what it did:

  > 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:47 PM
> To: r-help at r-project.org
> Subject: Re: [R] HELP me please with import of csv to R
> 
> Hello William,
> 
> - I used str()  and got this
> 
> 'data.frame':	290 obs. of  2 variables:
>  $ Kommuner: Factor w/ 289 levels "Ale","Alingsas",..: 34 40 44 79 95 99 132
> 162 169 173 ...
>  $ Skatt   : Factor w/ 177 levels "28,89","28,9",..: 86 7 47 67 74 25 24 23
> 85 74 ...
> 
>  - and summary()
> 
>  - got this
> 
> 
>  summary(skatter)
>      Kommuner       Skatt
>  Habo    :  2   33,4   :  9
>  Ale     :  1   31     :  6
>  Alingsas:  1   32,45  :  6
>  Almhult :  1   32     :  5
>  Alvdalen:  1   32,15  :  5
>  Alvesta :  1   33,2   :  5
>  (Other) :283   (Other):254
> 
> 
> 
> So obviously i have done something wrong. Do you know how i get it right?
> 
> 
> Thanks!
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Need-HELP-how-find-
> a-csv-file-tp4636019p4636204.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