[R] Data Set

Stephen Tucker brown_emu at yahoo.com
Mon Jul 23 12:56:29 CEST 2007


My bad... corrections (semantic and otherwise) always appreciated. I'm still
learning too.

I also forgot the alternative of using make.names() instead of manually
assigning 'more convenient' names.

input <- 
"Mydata,S-sharif,A site
1,45,34
2,66,45
3,79,56"

> dat <- read.csv(textConnection(input),check.names=FALSE)
> dat
  Mydata S-sharif A site
1      1       45     34
2      2       66     45
3      3       79     56
> names(dat)
[1] "Mydata"   "S-sharif" "A site"  
> names(dat) <- make.names(names(dat))
> names(dat)
[1] "Mydata"   "S.sharif" "A.site"  

Which, in the case of the data set, Monsoon, I don't know how it was created
originally but may be convenient to reassign names by

  names(Monsoon) <- make.names(names(Monsoon))



--- Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:

> On Sun, 2007-07-22 at 21:51 -0700, Stephen Tucker wrote:
> > It turns out that "-" and " " (space) are not valid variable names. 
> 
> They are valid names, the problem is that they aren't very convenient to
> use, as the OP discovered, because they need to be quoted.
> 
> Note that if using something like read.csv or read.table, R will correct
> these problem variable names for you when you import the data. If you
> read this file in for example:
> 
> "Mydata","S-sharif","A site"
> 1,45,34
> 2,66,45
> 3,79,56
> 
> using read.csv, you get easy to use names
> 
> > dat <- read.csv("temp.csv")
> > dat
>   Mydata S.sharif A.site
> 1      1       45     34
> 2      2       66     45
> 3      3       79     56
> 
> You can turn off this safety checking using the argument check.names =
> FALSE
> 
> G
> 
> -- 
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>  Gavin Simpson                 [t] +44 (0)20 7679 0522
>  ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
>  Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
>  Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
>  UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> 
> 
>



More information about the R-help mailing list